Reputation: 581
I am using DecimalFormat
class to format the double
input to required format.
DecimalFormat df = new DecimalFormat("#.00000000");
Then, I am using df.format(/*some value*/)
.
The problem is if I pass a double with more than 8 decimal part, it is formatting to 8 decimal part as required, but if I pass a value with less than 8 decimal part, it is not appending trailing 0
's. How to achieve that?
Example
df.format(12.67543456667)
will format it as 12.67543457
But,
df.format(12.675)
will format it to 12.675
only.
How to format it to 12.67500000
?
Upvotes: 1
Views: 760
Reputation: 96
The same logic should work.
DecimalFormat df = new DecimalFormat("#.00000000");
//System.out.println(df.format(12.67543456667));`
System.out.println(df.format(12.675));
output:-
12.67500000
Upvotes: 0
Reputation: 96
DecimalFormat df = new DecimalFormat("#.00000000");
should works. Try to change symbols for the default FORMAT locale or pass DecimalFormatSymbols
in constructor.
Upvotes: 1