aspose file tools*
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 Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "get decimal value" Watch "get decimal value" New topic
Author

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..


CJohn
Tom Reilly
Rancher

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:
http://www.coderanch.com/t/392641/java/java/decimal-part-float
you could also get it as float rest=number%1.


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

Joined: Oct 27, 2005
Posts: 19784
    
  20

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.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: get decimal value