Skip to content

Commit 5b00f0e

Browse files
patryk-kucharzpauljervis
authored andcommitted
BAEL-1600 Internationalization in Java 8 (eugenp#3902)
BigDecimal for currency formatting.
1 parent 1de8475 commit 5b00f0e

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

‎core-java-8/src/test/java/com/baeldung/internationalization/NumbersCurrenciesFormattingUnitTest.java‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import org.junit.Assert;
44
import org.junit.Test;
55

6+
import java.math.BigDecimal;
67
import java.text.DecimalFormat;
78
import java.text.DecimalFormatSymbols;
89
import java.text.NumberFormat;
@@ -32,7 +33,7 @@ public void givenDifferentLocalesAndDoubleAmount_whenCurrencyInstance_thenDiffer
3233
Locale usLocale = Locale.US;
3334
Locale plLocale = new Locale("pl", "PL");
3435
Locale deLocale = Locale.GERMANY;
35-
double number = 102_300.456d;
36+
BigDecimal number = new BigDecimal(102_300.456d);
3637

3738
NumberFormat usNumberFormat = NumberFormat.getCurrencyInstance(usLocale);
3839
NumberFormat plNumberFormat = NumberFormat.getCurrencyInstance(plLocale);
@@ -46,7 +47,7 @@ public void givenDifferentLocalesAndDoubleAmount_whenCurrencyInstance_thenDiffer
4647
@Test
4748
public void givenLocaleAndNumber_whenSpecificDecimalFormat_thenSpecificOutput() {
4849
Locale.setDefault(Locale.FRANCE);
49-
double number = 102_300.456d;
50+
BigDecimal number = new BigDecimal(102_300.456d);
5051

5152
DecimalFormat zeroDecimalFormat = new DecimalFormat("000000000.0000");
5253
DecimalFormat hashDecimalFormat = new DecimalFormat("###,###.#");
@@ -60,7 +61,7 @@ public void givenLocaleAndNumber_whenSpecificDecimalFormat_thenSpecificOutput()
6061
@Test
6162
public void givenLocaleAndNumber_whenSpecificDecimalFormatSymbols_thenSpecificOutput() {
6263
Locale.setDefault(Locale.FRANCE);
63-
double number = 102_300.456d;
64+
BigDecimal number = new BigDecimal(102_300.456d);
6465

6566
DecimalFormatSymbols decimalFormatSymbols = DecimalFormatSymbols.getInstance();
6667
decimalFormatSymbols.setGroupingSeparator('^');

0 commit comments

Comments
 (0)