I've noticed that small number floats, like 0.00000000345 end up getting converted to scientific notation, ie, 3.45e-9. This makes sense, but it looks like if I convert the float to a string (as I'd like to manipulate specific elements of the float according to its contents), the string itself adopts this notation.
Since it's now a string, it's easy enough to "translate" the contents back to a proper decimal number and manipulate it, but I was wondering if there is a built-in way that automatically allows for the saving of the actual decimal number as a string, rather than the scientific notation. Might not be, and I don't see anything in the documentation, but it can't hurt to ask.
With a round-trip to
BigDecimalyou can use itsto_smethod which allows the output format to be explicitly specified:Note that
Float#to_dattempts to determine the precision automatically which might fail for certain numbers:Here, it might help to convert the float to a string in advance: (you also don't need to require
bigdecimal/utilusing this variant)Keep in mind that those outputs don't show the float's actual value. The exact decimal value for
0.00000000345as a double-precision floating point number is: