0
  1. how to display any number to 5 decimal places. for example 0.0 to 0.00000, 12.63 to 12.63000.

  2. how to display any number to length 8. for example 12.1 to 12.10000, 2.1234567 to 2.123456

user2085965
  • 393
  • 2
  • 13
  • 33
  • 4
    see: http://stackoverflow.com/questions/153724/how-to-round-a-number-to-n-decimal-places-in-java – Alfie Jul 29 '13 at 16:18

5 Answers5

9
String.format("%.5f", 12.63)

returns 12.63000, etc

memowe
  • 2,656
  • 16
  • 25
jongusmoe
  • 676
  • 4
  • 16
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
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.

http://docs.oracle.com/javase/1.5.0/docs/api/java/lang/String.html#format%28java.lang.String,%20java.lang.Object...%29

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