how to display any number to 5 decimal places. for example 0.0 to 0.00000, 12.63 to 12.63000.
how to display any number to length 8. for example 12.1 to 12.10000, 2.1234567 to 2.123456
Asked
Active
Viewed 1,952 times
0

user2085965
- 393
- 2
- 13
- 33
-
4see: http://stackoverflow.com/questions/153724/how-to-round-a-number-to-n-decimal-places-in-java – Alfie Jul 29 '13 at 16:18
5 Answers
1
double number = (long) (number * 1e5) / 1e5;
or
double number = (long) (number * 1e8) / 1e8;

Peter Lawrey
- 525,659
- 79
- 751
- 1,130

bas
- 1,678
- 12
- 23
-
1You can add 0.5 for rounding, or use Math.round instead of casting. – Peter Lawrey Jul 29 '13 at 16:19
1
double value = 12.6357652133
value =Double.parseDouble(new DecimalFormat("##.########").format(value));

KOTIOS
- 11,177
- 3
- 39
- 66
0
check the length of the number. If the length is less than five or eight, concatenate the necessary amount of zeros. If the length is greater than five or eight, use the substring method. Hope this helps

hsan
- 151
- 4
0
Check this link. you will find the builtin function to format decimal number.

Ahmad Raza
- 2,850
- 1
- 21
- 37