I want to convert BigInteger number into a small scientific notation like 1.86e+6 and again reconvert that scientific notation into BigInteger number in Java. Please help.
相关问题
- Delete Messages from a Topic in Apache Kafka
- Jackson Deserialization not calling deserialize on
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
- Difference between Types.INTEGER and Types.NULL in
The easiest way is to use a
BigDecimal
to parse or output the scientific notation string.You can can do something like:
and reverse:
Update
If you need more user-defined output, then you can use
NumberFormatter
. Don't forget to set theLocale
to something likeLocale.ROOT
, so you won't get, say a comma as the decimal separator (which is what I got first, in the German locale). Example:The output of this is:
(Yes, BigIntegers can be unwieldy).
I don't know how big your values are, but the above works well on my Mac. Of course, using scientific notation with only a few decimal digits will lose a lot of precision.