closes #23
This commit is contained in:
@@ -2,6 +2,7 @@
|
|||||||
- in ram:ExchangedDocument: ram:name entfernen
|
- in ram:ExchangedDocument: ram:name entfernen
|
||||||
- updated javadoc
|
- updated javadoc
|
||||||
- fixed #104 nullpointerex when specifying no parameter
|
- fixed #104 nullpointerex when specifying no parameter
|
||||||
|
- closed #23
|
||||||
|
|
||||||
1.7.2
|
1.7.2
|
||||||
=====
|
=====
|
||||||
|
|||||||
@@ -77,7 +77,7 @@ public class ZUGFeRD2PullProvider implements IXMLProvider, IProfileProvider {
|
|||||||
public void setTest() {
|
public void setTest() {
|
||||||
}
|
}
|
||||||
|
|
||||||
private String nDigitFormat(BigDecimal value, int scale) {
|
public static String nDigitFormat(BigDecimal value, int scale) {
|
||||||
/*
|
/*
|
||||||
* I needed 123,45, locale independent.I tried
|
* I needed 123,45, locale independent.I tried
|
||||||
* NumberFormat.getCurrencyInstance().format( 12345.6789 ); but that is locale
|
* NumberFormat.getCurrencyInstance().format( 12345.6789 ); but that is locale
|
||||||
@@ -92,16 +92,6 @@ public class ZUGFeRD2PullProvider implements IXMLProvider, IProfileProvider {
|
|||||||
* http://docs.oracle.com/javase/tutorial/i18n/format/decimalFormat.html in the
|
* http://docs.oracle.com/javase/tutorial/i18n/format/decimalFormat.html in the
|
||||||
* end I decided to calculate myself and take eur+sparator+cents
|
* end I decided to calculate myself and take eur+sparator+cents
|
||||||
*
|
*
|
||||||
* This function will cut off, i.e. floor() subcent values Tests:
|
|
||||||
* System.err.println(utils.currencyFormat(new BigDecimal(0),
|
|
||||||
* ".")+"\n"+utils.currencyFormat(new BigDecimal("-1.10"),
|
|
||||||
* ",")+"\n"+utils.currencyFormat(new BigDecimal("-1.1"),
|
|
||||||
* ",")+"\n"+utils.currencyFormat(new BigDecimal("-1.01"),
|
|
||||||
* ",")+"\n"+utils.currencyFormat(new BigDecimal("20000123.3489"),
|
|
||||||
* ",")+"\n"+utils.currencyFormat(new BigDecimal("20000123.3419"),
|
|
||||||
* ",")+"\n"+utils.currencyFormat(new BigDecimal("12"), ","));
|
|
||||||
*
|
|
||||||
* results 0.00 -1,10 -1,10 -1,01 20000123,34 20000123,34 12,00
|
|
||||||
*/
|
*/
|
||||||
value = value.setScale(scale, BigDecimal.ROUND_HALF_UP); // first, round so that e.g.
|
value = value.setScale(scale, BigDecimal.ROUND_HALF_UP); // first, round so that e.g.
|
||||||
// 1.189999999999999946709294817992486059665679931640625
|
// 1.189999999999999946709294817992486059665679931640625
|
||||||
@@ -111,25 +101,29 @@ public class ZUGFeRD2PullProvider implements IXMLProvider, IProfileProvider {
|
|||||||
|
|
||||||
DecimalFormatSymbols otherSymbols = new DecimalFormatSymbols();
|
DecimalFormatSymbols otherSymbols = new DecimalFormatSymbols();
|
||||||
otherSymbols.setDecimalSeparator('.');
|
otherSymbols.setDecimalSeparator('.');
|
||||||
DecimalFormat dec = new DecimalFormat("0." + new String(repeat), otherSymbols);
|
String baseFormat="0";
|
||||||
|
if (scale>0) {
|
||||||
|
baseFormat+=".";
|
||||||
|
}
|
||||||
|
DecimalFormat dec = new DecimalFormat(baseFormat + new String(repeat), otherSymbols);
|
||||||
return dec.format(value);
|
return dec.format(value);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private String vatFormat(BigDecimal value) {
|
private String vatFormat(BigDecimal value) {
|
||||||
return nDigitFormat(value, 2);
|
return ZUGFeRD2PullProvider.nDigitFormat(value, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
private String currencyFormat(BigDecimal value) {
|
private String currencyFormat(BigDecimal value) {
|
||||||
return nDigitFormat(value, 2);
|
return ZUGFeRD2PullProvider.nDigitFormat(value, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
private String priceFormat(BigDecimal value) {
|
private String priceFormat(BigDecimal value) {
|
||||||
return nDigitFormat(value, 4);
|
return ZUGFeRD2PullProvider.nDigitFormat(value, 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
private String quantityFormat(BigDecimal value) {
|
private String quantityFormat(BigDecimal value) {
|
||||||
return nDigitFormat(value, 4);
|
return ZUGFeRD2PullProvider.nDigitFormat(value, 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
65
src/test/java/org/mustangproject/ZUGFeRD/BaseTest.java
Normal file
65
src/test/java/org/mustangproject/ZUGFeRD/BaseTest.java
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
/** **********************************************************************
|
||||||
|
*
|
||||||
|
* Copyright 2019 Jochen Staerk
|
||||||
|
*
|
||||||
|
* Use is subject to license terms.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||||
|
* use this file except in compliance with the License. You may obtain a copy
|
||||||
|
* of the License at http://www.apache.org/licenses/LICENSE-2.0.
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
*
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*
|
||||||
|
*********************************************************************** */
|
||||||
|
package org.mustangproject.ZUGFeRD;
|
||||||
|
|
||||||
|
import junit.framework.Test;
|
||||||
|
import junit.framework.TestSuite;
|
||||||
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
|
import org.junit.FixMethodOrder;
|
||||||
|
import org.junit.runners.MethodSorters;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.Calendar;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.GregorianCalendar;
|
||||||
|
|
||||||
|
public class BaseTest extends TestCase {
|
||||||
|
/**
|
||||||
|
* Create the test case
|
||||||
|
*
|
||||||
|
* @param testName name of the test case
|
||||||
|
*/
|
||||||
|
public BaseTest(String testName) {
|
||||||
|
super(testName);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the suite of tests being tested
|
||||||
|
*/
|
||||||
|
public static Test suite() {
|
||||||
|
return new TestSuite(BaseTest.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testCorrectDigits() {
|
||||||
|
assertEquals("0.00", ZUGFeRD2PullProvider.nDigitFormat(new BigDecimal(0),2));
|
||||||
|
assertEquals("-1.10", ZUGFeRD2PullProvider.nDigitFormat(new BigDecimal("-1.10"),2));
|
||||||
|
assertEquals("-1.10", ZUGFeRD2PullProvider.nDigitFormat(new BigDecimal("-1.1"),2));
|
||||||
|
assertEquals("-1.01", ZUGFeRD2PullProvider.nDigitFormat(new BigDecimal("-1.01"),2));
|
||||||
|
assertEquals("20000123.35", ZUGFeRD2PullProvider.nDigitFormat(new BigDecimal("20000123.3489"),2));
|
||||||
|
assertEquals("20000123.34", ZUGFeRD2PullProvider.nDigitFormat(new BigDecimal("20000123.3419"),2));
|
||||||
|
assertEquals("12.00", ZUGFeRD2PullProvider.nDigitFormat(new BigDecimal("12"),2));
|
||||||
|
assertEquals("12", ZUGFeRD2PullProvider.nDigitFormat(new BigDecimal("12"),0));
|
||||||
|
assertEquals("20000123.342", ZUGFeRD2PullProvider.nDigitFormat(new BigDecimal("20000123.3419"),3));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user