Skip to content

Round ​

Rounds x to the nearest integer, or to the nearest multiple of a.

✓ checked against that system · ! checked, with disagreements (hover a chip)WikipediaRoundingMathWorldNearestIntegerFunctionRoundingWikidataQ663208Wolfram LanguageRound✓
Round(x)rounds x to the nearest integer, a tie to the even one.
SageMathround(x)SymPyround(x)mpmathnint(x)Juliaenumeratio_round(x)Rustround(x)
Round(x, a)rounds to the nearest multiple of the step a.
Round(x, a?)Rounds x to the nearest integer, or to the nearest multiple of a.
Typed signatures
TypePackageApplies
(x: real | signed_infinity | ~oo, step: real?) -> real | signed_infinity | ~ooanalyticreplaces compute-enginealways
(x: real | signed_infinity | ~oo, step: real?) -> real | signed_infinity | ~oocompute-enginealways
(any, any?) -> anystructuresreplaces analyticalways

Domain: Arithmetic

Details
  • Rounds to the nearest integer, with ties (an exact .5) going to the even one, as in Wolfram, Sage, SymPy, mpmath and Python: Round(2.5)=2\mathrm{Round}(2.5) = 2, Round(3.5)=4\mathrm{Round}(3.5) = 4 and Round(−2.5)=−2\mathrm{Round}(-2.5) = -2.
  • A second argument a rounds to the nearest multiple of a, as in Wolfram: Round(226,10)=230\mathrm{Round}(226, 10) = 230 and Round(3.14159,1/100)=157/50\mathrm{Round}(3.14159, 1/100) = 157/50. A step of 1 agrees with the 1-argument form.
  • Threads element-wise over a list.
  • Floor and Ceil take a step the same way.
  • Differs from Rust's round, and from compute-engine's own default, in the tie rule: both send a tie away from zero, so Round(5/2)=3\mathrm{Round}(5/2) = 3 there where it is 22 here. Only exact ties differ.
  • Python's round(x, n) counts digits: its round(x, 2) is Round(x,1/100)\mathrm{Round}(x, 1/100) here.
  • Ties follow the engine's roundingTies setting, which every engine we ship sets to to-even; compute-engine's default is away from zero.

Examples

3 more kept as data, checked against the oracles
Basic #
live ↗
Inround(72)\mathrm{round}(\frac{7}{2})Out44
live ↗
Inround(3.5)\mathrm{round}(3.5)Out44

Integers pass through unchanged

live ↗
Inround(5)\mathrm{round}(5)Out55

A second argument rounds to the nearest multiple of it: a step of 1/100

live ↗
Inround(3.141 59,1100)\mathrm{round}(3.141\,59, \frac{1}{100})Out15750\frac{157}{50}

Threads element-wise over a list

live ↗
Inround([1.5,−1.5,2.4])\mathrm{round}(\bigl\lbrack1.5, -1.5, 2.4\bigr\rbrack)Out[2,−2,2]\bigl\lbrack2, -2, 2\bigr\rbrack
live ↗
Inround(2.4)\mathrm{round}(2.4)Out22
live ↗
Inround(2.6)\mathrm{round}(2.6)Out33
live ↗
Inround(5.37)\mathrm{round}(5.37)Out55
live ↗
Inround(−3.7)\mathrm{round}(-3.7)Out−4-4
Scope #

Stays symbolic

live ↗
Inround(x)\mathrm{round}(x)Outround(x)\mathrm{round}(x)

To the nearest multiple of ten

live ↗
Inround(226,10)\mathrm{round}(226, 10)Out230230

An exact argument rounds to an exact rational

live ↗
Inround(2,110 000)\mathrm{round}(\sqrt{2}, \frac{1}{10\,000})Out7 0715 000\frac{7\,071}{5\,000}

Evaluates at an exact constant: Round(π)=3\mathrm{Round}(\pi) = 3

live ↗
Inround(π)\mathrm{round}(π)Out33

100e≈271.83100e \approx 271.83 rounds to 272

live ↗
Inround(100e)\mathrm{round}(100e)Out272272

Rounds the real and imaginary parts separately

live ↗
Inround(5.37−1.3i)\mathrm{round}(5.37-1.3i)Out5−i5-i

The step can be any size: 226 is nearest to 200 among the multiples of 100

live ↗
Inround(226,100)\mathrm{round}(226, 100)Out200200
Applications #

Rounding a price to the nearest cent: 19.995 rounds up to 20

live ↗
Inround(19.995,1100)\mathrm{round}(19.995, \frac{1}{100})Out2020
Properties #

1234 is nearest to 1200 among the multiples of 100

live ↗
Inround(1 234,100)=1 200\mathrm{round}(1\,234, 100)=1\,200OutTrue\mathrm{True}

A step of 1 matches the 1-argument form

live ↗
Inround(3.141 59,1)=round(3.141 59)\mathrm{round}(3.141\,59, 1)=\mathrm{round}(3.141\,59)OutTrue\mathrm{True}
Possible issues #

Rounds a tie to the even integer, as banker's rounding does: 2.5 rounds to 2, not 3

live ↗
Inround(2.5)\mathrm{round}(2.5)Out22

...and by the same rule, -2.5 rounds to -2, not -3

live ↗
Inround(−2.5)\mathrm{round}(-2.5)Out−2-2

The same tie-breaking rule on an exact rational, not just a float: 5/2 rounds to 2

live ↗
Inround(52)\mathrm{round}(\frac{5}{2})Out22

An exact half rounds to the even integer as well: 1/2 rounds to 0

live ↗
Inround(12)\mathrm{round}(\frac{1}{2})Out00

Round(ComplexInfinity) is ComplexInfinity: rounding an infinite magnitude with no direction is still that magnitude, the same convention as Ceil and Floor

live ↗
Inround(∞~)\mathrm{round}(\tilde∞)Out∞~\tilde∞

Known value · Wolfram Round[ComplexInfinity]

About
Examples27
Checked againstWolfram Language 27 agreeSageMath 16 agree4 errorSymPy 25 agree2 errormpmath 17 agreeJulia 17 agreeRust 11 agree5 differ
CrosswalkWikipediaMathWorld ×2WikidataWolfram LanguageSageMathSymPympmathJuliaRust

Implementation

mappedsympypackages/oracle/src/mappings.ts

SymPy's round, like Wolfram's, sends a tie to the even integer and rounds a complex number part by part.

mappedsympypackages/oracle/src/mappings.ts
mappedmpmathpackages/oracle/src/mappings.ts

mpmath rounds half to even.

mappedsagepackages/oracle/src/mappings.ts
mappedjuliapackages/oracle/src/mappings.ts
mappedrustpackages/oracle/src/mappings.ts

Ties go away from zero, as num-rational's round and std's do.

See also: Floor, Ceil, Clamp