• Post Reply Bookmark Topic Watch Topic
  • New Topic

get decimal value  RSS feed

 
Ranch Hand
Posts: 47
Eclipse IDE Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i'm having a Float number (i.e) 26.46

i want to get those number(46) after decimal place..

Please guide me..
 
Rancher
Posts: 618
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One way is to put the float value into an integer value, which removes the fractional part, and then subtract the integer from the float to get the fractional part.
 
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this topic may be useful too:
http://www.coderanch.com/t/392641/java/java/decimal-part-float
you could also get it as float rest=number%1.
 
Sheriff
Posts: 21136
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And then just multiply by 10^(number of digits) and round. So to get 3 digits:
Another way that will always return you all decimals is using Strings:
This will not work, however, if scientific notation (with E, e.g. 4.6E-1) is used. BigDecimal can then help you out, with its toPlainString method.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!