How can I tell if a decimal number represented as a String will fit in a double?

I'm parsing a String value which I know contains a number.

If it only contains digits and it's between Integer.MIN_VALUE and Integer.MAX_VALUE I'm parsing it as an int, similarly for long otherwise I'm using BigInteger.

If it contains a decimal value I'd either like to parse it as a double or as a BigDecimal.

Can I test if the numeric value in the String "fits" into a double and is therefore safe to parse as a double, or whether it needs to be held in a BigDecimal to prevent loss of precision?...

Read More »

By: StackOverFlow - Wednesday, 7 November

Related Posts