Created
March 5, 2019 10:14
-
-
Save marschall/d8bfee727e025af122991241e4ad89f4 to your computer and use it in GitHub Desktop.
Portable Decimal Formatting
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class PortableDecimalFormatTest { | |
@Test | |
void decimalFormat() { | |
Locale switzerland = new Locale("de", "CH"); | |
DecimalFormat format = (DecimalFormat) NumberFormat.getInstance(switzerland); | |
format.applyPattern("#,##0.00"); | |
DecimalFormatSymbols decimalFormatSymbols = format.getDecimalFormatSymbols(); | |
decimalFormatSymbols.setGroupingSeparator('\''); | |
// important because #getDecimalFormatSymbols() returns a clone | |
format.setDecimalFormatSymbols(decimalFormatSymbols); | |
String formatted = format.format(new BigDecimal("1234567.8")); | |
assertEquals("1'234'567.80", formatted); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment