I do not see anything like it in Float. Float is basically a wrapper for the native double type and given the usual binary / decimal problems, I am not surprised that Float does not allow you to manipulate significant digits.
However, BigDecimal in the standard library really understands significant numbers, but again, I do not see anything that allows you to directly change the significant numbers in BigDecimal: you can ask for it, but you cannot change it. But you can spoof this using the no-op version of the mult or add methods:
require 'bigdecimal' a = BigDecimal.new('11.2384') a.mult(1, 2)
The second argument to these methods:
If less than the number of significant digits of the result is indicated, the result is rounded to this number of digits in accordance with BigDecimal.mode .
Using BigDecimal will be slower, but it may be your only choice if you need fine-grained control or if you need to avoid the usual floating point problems.
mu is too short
source share