Hints for Java'ers who also hates problems like this and doesn't want to write automation-based solution.
new BigDecimal(line1) - it's almost cool, but you need some fixes before use constructor 1. Check for empty fraction case, e.g. "1.", "1.e2", "1.E2" - these are NANs according P1074 grammar, but OK according BigDecimal grammar (this is the only difference in grammars). 2. Fix big exponent to something smaller, for BigDecimal to be able to parse it e.g. e1000000000000 => e1000 e-1000000000000 => e-1000