I\'m trying to get rid of unnecessary symbols after decimal seperator of my double value. I\'m doing it this way:
DecimalFormat format = new DecimalFormat(\"
For the ',
' instead of the '.
' , you'd have to change the locale.
For the number of decimals, use setMaximumFractionDigits(int newValue)
.
For the rest, see the javadoc.
By
get rid of unnecessary symbols after decimal seperator of my double value
do you actually mean you want to round to e.g. the 5th decimal? Then just use
value = Math.round(value*1e5)/1e5;
(of course you can also Math.floor(value*1e5)/1e5
if you really want the other digits cut off)
My code function :
private static double arrondi(double number){
DecimalFormatSymbols symbols = DecimalFormatSymbols.getInstance();
symbols.setDecimalSeparator('.');
DecimalFormat format = new DecimalFormat("#.#####", symbols);
return Double.valueOf(format.format(number));
}
Use Locale.getDefault()
to get your system's decimal separator which you can also set. You can't have two different separators at the same time since the other is then usually used as the separator for thousands: 2.001.000,23 <=> 2,001,000.23