wood burning stoves 2.0*
The moose likes Java in General and the fly likes method to find # of digits after decimal Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "method to find # of digits after decimal" Watch "method to find # of digits after decimal" New topic
Author

method to find # of digits after decimal

varun bihani
Ranch Hand

Joined: Aug 11, 2003
Posts: 96
Is there any method that will return the number of digits after decimal in double number.
eg, I want to write a method that takes "double number " as input.. I want to know if that number/parameter has any decimal numbers.. ?and how many ?

if parameter is '3' , method should return '0' ..
if parameter is 3.23, it should return '2'..


<a href="http://www.galaxyweblinks.com" target="_blank" rel="nofollow">www.galaxyweblinks.com</a><br /><a href="http://www.freechatcode.com" target="_blank" rel="nofollow">www.freechatcode.com</a><br /><a href="http://www.onlinefamilytreemaker.com" target="_blank" rel="nofollow">www.onlinefamilytreemaker.com</a>
David McCombs
Ranch Hand

Joined: Oct 17, 2006
Posts: 212
Not directly, that i know of. It is not a difficult method to write.

Convert the double to a String.

Take the substring you need, return the length. There are special cases to consider, ie 3.0.


"Should array indices start at 0 or 1? My compromise of 0.5 was rejected without, I thought, proper consideration."- Stan Kelly-Bootle
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: method to find # of digits after decimal
 
Similar Threads
scaling a Double
Aline decimals
Double Value
validating double value using regular expression
Leading Spaces instead of zeros?