Skip to main content

computed_float_text

Function computed_float_text 

Source
pub fn computed_float_text(
    value: &str,
    significant: u8,
    spelling: &FloatArithmetic<'_>,
) -> String
Expand description

A floating number as %.{significant}g writes it, computed on an engine with no printf.

The power of ten is the floor of the magnitude’s base-ten logarithm, less one where the logarithm rounded up past a magnitude just under a power of ten. The significant digits are the magnitude divided by that power and scaled to a whole number of significant digits, rounded; a rounding that carries into one more digit, as 9.999… does, adds one to the power, and the extra digit, a zero, is never read. float_text lays the pieces out and signed_float_text adds the sign. A zero never reaches the logarithm.

Uses NULLIF, ABS, ROUND with two arguments and CASE besides the spellings it is handed.