Std.Fmt.fixed
1 declaration
fn
fixed: &Std.Fmt.Spec -> Decimal -> Int -> StrThis is a callable function.
What it does
An exact fraction shaped by the spec, shown to a fixed number of places.
A Decimal rather than a Float, because a figure shown to two places is
almost always money or a measurement, and a float cannot hold those exactly
— a total that renders as 0.30 after adding 0.10 three times is the
error this avoids by not admitting the type that causes it.
Rounding is half away from zero, which is the rounding a reader does by
hand. Asking for more places than the value carries pads with zeros, so a
column of figures lines up on its point.
Read the signature
- The text after the name is the type checked by Pudu.
- Read arrows from left to right: inputs come first, and the final type is returned.
- & borrows a value for this call instead of moving or copying it.
