I would like to check whether the double value has exponent or not. There is no such method in Math
using which I can determine. I do not want to convert it to string and then use indexOf()
or contains()
methods.
Thanks in advance.
I would like to check whether the double value has exponent or not. There is no such method in Math
using which I can determine. I do not want to convert it to string and then use indexOf()
or contains()
methods.
Thanks in advance.
Internally all doubles are represented the same way. (They all have binary exponents, though you don't see those.)
Whether they are printed with an exponent or not is only a formatting issue. It is not meaningful to test whether the double itself has an exponent. The right way to test whether it is formatted with an exponent it is to take the string representation and use str.contains("E") || str.contains("e")
.
You can use a format string or DecimalFormat object to get some control over how the double is converted to a String. E.g., String.format("%f", 9.7561E-4)
(number with exponent) returns the string 0.000976
(no exponent).