This week's book giveaway is in the OCAJP 8 forum.
We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes get decimal value Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "get decimal value" Watch "get decimal value" New topic

get decimal value

Carl John
Ranch Hand

Joined: Jun 14, 2010
Posts: 47

i'm having a Float number (i.e) 26.46

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

Please guide me..

Tom Reilly

Joined: Jun 01, 2010
Posts: 618
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.
Fiorenza Oppici
Ranch Hand

Joined: Jul 22, 2010
Posts: 38
this topic may be useful too:
you could also get it as float rest=number%1.

[I study here]
Regards, FiĆ²
Rob Spoor

Joined: Oct 27, 2005
Posts: 20136

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.

How To Ask Questions How To Answer Questions
I agree. Here's the link:
subject: get decimal value
It's not a secret anymore!