Softanza
StartFrançais
Softanza
Reference · stzNumber

RoundedTo()

A copy rounded to the given number of decimals; the original is unchanged.

Basic examples (2)

Softanza
# RoundedTo still rounds half-up
? (new stzNumber("2.5")).RoundedTo(0)
# ...and still tidies trailing zeros
? (new stzNumber("12.456")).RoundedTo(4)
# ...and still gets 100.4 right
? (new stzNumber("100.4")).RoundedTo(0)
Output
3
12.456
100

run on 2026-10-02 04:23 inside the library at commit 0e72e2e2c; taken from numeric_tie_rule_narrated.ring(opens in a new tab)

Softanza
# 0.5 rounds to 1
? (new stzNumber("0.5")).RoundedTo(0)
# 1.5 rounds to 2
? (new stzNumber("1.5")).RoundedTo(0)
# 2.5 rounds to 3 -- half-even would say 2
? (new stzNumber("2.5")).RoundedTo(0)
# 3.5 rounds to 4
? (new stzNumber("3.5")).RoundedTo(0)
# and a negative tie goes away from zero too
? (new stzNumber("-1.5")).RoundedTo(0)
Output
1
2
3
4
-2

run on 2026-10-02 04:23 inside the library at commit 0e72e2e2c; taken from numeric_rounding_narrated.ring(opens in a new tab)

Scope (2)

Softanza
oPi = new stzNumber("12.456")
# asking for more places than exist adds none
? oPi.RoundedTo(4)
# ...however many more
? oPi.RoundedTo(5)
# asking for fewer rounds
? oPi.RoundedTo(2)
# ...and fewer still
? oPi.RoundedTo(1)
# ...down to a whole number
? oPi.RoundedTo(0)
# a value whose places are all zeros tidies to the integer
? (new stzNumber("1.005")).RoundedTo(2)
Output
12.456
12.456
12.46
12.5
12
1

run on 2026-10-02 04:23 inside the library at commit 0e72e2e2c; taken from numeric_rounding_narrated.ring(opens in a new tab)

Softanza
# ten point four rounds to ten
? (new stzNumber("10.4")).RoundedTo(0)
# ...not to one
? (new stzNumber("10.4")).RoundedTo(0) != "1"
# a hundred point four rounds to a hundred
? (new stzNumber("100.4")).RoundedTo(0)
# ...and ten point oh four to ten
? (new stzNumber("10.04")).RoundedTo(0)
# a value that rounds to zero says zero
? (new stzNumber("0.125")).RoundedTo(0)
# rounding up past the zero still works
? (new stzNumber("20.6")).RoundedTo(0)
# ...and carries
? (new stzNumber("1000.7")).RoundedTo(0)
# negatives keep their magnitude
? (new stzNumber("-10.4")).RoundedTo(0)
Output
10
1
100
10
0
21
1001
-10

run on 2026-10-02 04:23 inside the library at commit 0e72e2e2c; taken from numeric_rounding_narrated.ring(opens in a new tab)

The extensions of this method

Each extension, and whether it exists for this method; an extension that exists combines with the others (FindSTCS).

Extension
Exists
What it adds · The names
Q
no
does what the method does, then returns the object, so the call can be chained
QQ
no
chains on the next, more specific type of object (the Q ladder)
QQQ
no
chains on the most specific type of object (the Q ladder)
QRT
no
returns the result as an object of the requested type
CS
no
takes a case-sensitivity flag
ST
no
takes the position to start from (StartingAt)
IB
no
takes bounds that are included (IncludingBounds)
XT
yes
the extended form: more parameters than the base method · RoundedToXT
XTT
no
yet another extension: a further extended form, after XT
Z
no
includes the position in what it returns
ZZ
no
returns positions as sections, [start, end]
W
no
selects by a condition
WF
no
selects by a condition, with the expressive keywords (@NextItem, @PreviousItem...)
D
no
takes a direction, forward or backward (Directional)
F
no
takes a function (the condition or the update is given as a function); the forms document also uses F for the future form, which defers the action
Many
no
works on a collection of items instead of one (the plural form)
Except
no
takes exceptions, what to leave out (the exceptional form)
U
no
returns the result without duplication

Every example is a test file of the library, run inside the library for this page; only those whose output kept every promise their file wrote are shown.

See also