Round

roundMicronode

Rounds a number to a fixed number of decimal places. Folded at compile time: the result is spliced into the surrounding text as characters, so no node reaches the renderer and the number cannot be re-formatted, animated or bound to afterwards. Rounding is half away from zero.

Explained in:Value primitives

#Attributes

placesImplicit
number
Decimal places to keep. Zero rounds to a whole number.Can be written as shorthand: round:value
Default0

#Allowed content

Body { }A number

#Examples

The correlation settles at !round:2{0.8734}.
!round{3.7}

#Notes

  • !round:2{3.14159} folds to 3.14; !round{3.7} to 4; !round:2{3.1} to 3.1 — a result renders as the shortest exact decimal, with no trailing zeros.
  • A fold cannot read a live value: !round:2{#f.slope} is a compile error, because a binding has no value until the document renders. Round a live number with !value's own digits instead.