How to find out the length or number of digits of the fractional part of a decimal number?
I see several approbations, for example. with the following lines:
public static int getNumberOfFractionDigits(Number number) {
Double fractionPart = number.doubleValue() - number.longValue();
return fractionPart.toString().length() - 2;
}
But what is the best way to determine the length?
I could introduce some problems if I use strings, for example. because the format of the language and number may differ from system to system. Is there a good way to calculate it? Maybe without iterations?
Thanks in advance.
source
share