Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Digits after the decimal

807588Feb 1 2009 — edited Feb 2 2009
I want to write code that finds the number of digits after the decimal in a double number. This is what I'm currently doing:
double d;...
...String doubleString = Double.toString(d);
int digitsAfterDecimal = doubleString.length() - doubleString.indexOf('.') - 1;
But when the double reaches a certain point the double goes into scientific notation. How can I get the number of digits even when the string goes into scientific notation? Is there a better way besides using a string?

Comments

Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Mar 2 2009
Added on Feb 1 2009
5 comments
328 views