I need to process a CSV. The users define if a column has floats or doubles. The thing is, sometimes they put doubles in a float column, and after it rounds the values and the users only find out later.
I'd like to not let this behaviour happen if it's at all possible.
So, if we try to store a number too big on a float, it doesn't round it but instead throws an exception.
I'm aware that there are some numbers that cannot be represented correctly like when we do 0.1 + 0.2, this is not what I'm trying to avoid.
I've considered storing everything on a BigDecimal, but currently that has too much impact on the codebase so I'd prefer to avoid it for now.
Edit:
I'm aware there are rounding errors. But assuming the systems are using IEEE 754 floats or doubles, the representation is the same. So a "0.25" float in a system is going to continue to have the same rounding error after imported.
BigDecimals, just create one and compare against the largestfloat, then throw an exception.floatordoublemath. The only things that double/float can store without any loss is anything that can be expressed asX/2^Ywhere X can be whatever. So, 5/8ths can be stored perfectly (because 8 is2*2*2). Think about decimal. The same thing happens there, except there it'sX/(2^Y*5^Z)(because 2 and 5 are the divisors of 10, and decimal = base 10).