Change DecimalFormat locale
You can specify locale for DecimalFormat this way: DecimalFormatSymbols symbols = new DecimalFormatSymbols(Locale.US); DecimalFormat format = new DecimalFormat(“##.########”, symbols);
You can specify locale for DecimalFormat this way: DecimalFormatSymbols symbols = new DecimalFormatSymbols(Locale.US); DecimalFormat format = new DecimalFormat(“##.########”, symbols);
Try this // Create a DecimalFormat that fits your requirements DecimalFormatSymbols symbols = new DecimalFormatSymbols(); symbols.setGroupingSeparator(‘,’); symbols.setDecimalSeparator(‘.’); String pattern = “#,##0.0#”; DecimalFormat decimalFormat = new DecimalFormat(pattern, symbols); decimalFormat.setParseBigDecimal(true); // parse the string BigDecimal bigDecimal = (BigDecimal) decimalFormat.parse(“10,692,467,440,017.120”); System.out.println(bigDecimal); If you are building an application with I18N support you should use DecimalFormatSymbols(Locale) Also keep in mind … Read more
If you want that for display purposes, use java.text.DecimalFormat: new DecimalFormat(“#.##”).format(dblVar); If you need it for calculations, use java.lang.Math: Math.floor(value * 100) / 100;
You can change the separator either by setting a locale or using the DecimalFormatSymbols. If you want the grouping separator to be a point, you can use an european locale: NumberFormat nf = NumberFormat.getNumberInstance(Locale.GERMAN); DecimalFormat df = (DecimalFormat)nf; Alternatively you can use the DecimalFormatSymbols class to change the symbols that appear in the formatted numbers … Read more