File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes How to find number of decimal places? 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 » Beginning Java
Bookmark "How to find number of decimal places?" Watch "How to find number of decimal places?" New topic
Author

How to find number of decimal places?

Ajith George
Ranch Hand

Joined: Dec 22, 2005
Posts: 109
How can i find number of decimal places in a double value.
example number of decimal places in 0.0005.

Thanks in advance.


SCJP 1.4, Brainbench
LinkedIn - Blog
Keith Lynn
Ranch Hand

Joined: Feb 07, 2005
Posts: 2367
You could convert it to a String, find the index of the . and then find the difference between that index and the length of the String.
Ajith George
Ranch Hand

Joined: Dec 22, 2005
Posts: 109
But the double number passed in to the method is automatically converted in to the format 5.0E-6 for .000005 . So that idea is not working. Any other suggstions, please help.
Keith Lynn
Ranch Hand

Joined: Feb 07, 2005
Posts: 2367
Well if it's in scientific notation, you should be able to use the exponent to figure out the number of decimal places.
Ajith George
Ranch Hand

Joined: Dec 22, 2005
Posts: 109
But how can i use this exponebt number. itried the following code

But some garbage value too is coming with variable theChar.
What should i do?
Keith Lynn
Ranch Hand

Joined: Feb 07, 2005
Posts: 2367
Here is a way to start if you have the number in scientific notation.

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to find number of decimal places?
 
Similar Threads
Urgent A method in Java which rounds 18 places to 8 places after decimal
floating point round to 2.
Dividing Ints
Problem with DecimalFormat
Excel display integer instead of double