@@ -566,35 +566,44 @@ <h5 id="round">
566566 < i > ⇒ Big</ i > </ code >
567567 </ h5 >
568568 < p >
569- < code > dp</ code > ? : < i > number</ i > : integer, 0 to 1e+6 inclusive
569+ < code > dp</ code > ? : < i > number</ i > : integer, -1e+6 to 1e+6 inclusive
570570 < br />
571571 < code > rm</ code > ? : < i > number</ i > : 0, 1, 2 or 3
572572 </ p >
573573 < p >
574574 Returns a Big number whose value is the value of this Big number rounded
575575 using rounding mode < code > rm</ code > to a maximum of < code > dp</ code >
576- decimal places.
576+ decimal places, or, if < code > dp</ code > is negative, rounded to an
577+ integer which is a multiple of < code > 10**-dp</ code > .
577578 </ p >
578579 < p >
579- if < code > dp</ code > is omitted or is undefined, the return value is
580- < code > n </ code > rounded to a whole number.< br />
580+ if < code > dp</ code > is omitted or is undefined, the return value is the value of this Big
581+ number rounded to a whole number.< br />
581582 if < code > rm</ code > is omitted or is undefined, the current
582583 < a href ='#rm '> < code > Big.RM</ code > </ a > setting is used.
583584 </ p >
584585 < p >
585586 Throws if < code > dp</ code > or < code > rm</ code > is invalid.
586587 </ p >
587588 < pre >
589+ down = 0
590+ half_up = 1
591+ half_even = 2
592+ up = 3
593+
588594x = 123.45
589595Math.round(x) // 123
596+
590597y = new Big(x)
591598y.round() // '123'
592599y.round(2) // '123.45'
593600y.round(10) // '123.45'
594- y.round(1, 0) // '123.4'
595- y.round(1, 1) // '123.5'
596- y.round(1, 2) // '123.4'
597- y.round(1, 3) // '123.5'
601+ y.round(1, down) // '123.4'
602+ y.round(1, half_up) // '123.5'
603+ y.round(1, half_even) // '123.4'
604+ y.round(1, up) // '123.5'
605+ y.round(-1, down) // '120'
606+ y.round(-2, up) // '200'
598607y // '123.45'</ pre >
599608
600609
@@ -642,7 +651,7 @@ <h5 id="toE">
642651 < p > < code > dp</ code > ? : < i > number</ i > : integer, 0 to 1e+6 inclusive</ p >
643652 < p >
644653 Returns a string representing the value of this Big number in exponential
645- notation to a fixed number of decimal places < code > dp</ code > .
654+ notation to a fixed number of < code > dp</ code > decimal places .
646655 </ p >
647656 < p >
648657 If the value of this Big number in exponential notation has more digits to
@@ -686,7 +695,7 @@ <h5 id="toF">
686695 </ p >
687696 < p >
688697 Returns a string representing the value of this Big number in normal
689- notation to a fixed number of decimal places < code > dp</ code > .
698+ notation to a fixed number of < code > dp</ code > decimal places .
690699 </ p >
691700 < p >
692701 If the value of this Big number in normal notation has more digits to the
@@ -731,7 +740,7 @@ <h5 id="toP">
731740 < p > < code > sd</ code > ? : < i > number</ i > : integer, 1 to 1e+6 inclusive</ p >
732741 < p >
733742 Returns a string representing the value of this Big number to the
734- specified number of significant digits < code > sd</ code > .
743+ specified number of < code > sd</ code > significant digits .
735744 </ p >
736745 < p >
737746 If the value of this Big number has more digits than is specified by
@@ -1071,6 +1080,8 @@ <h6>
10711080x = new Big('987.654321')
10721081len = x.c.length // 9
10731082if (len > 6) x.c.length = 6
1083+ // Check for and remove any trailing zeros in the coefficient array.
1084+ while (x.c[x.c.length - 1] === 0 && x.c.length > 1) x.c.pop();
10741085x // 987.654
10751086</ pre >
10761087 < br />
@@ -1170,6 +1181,7 @@ <h6>Why are trailing fractional zeros removed from Big numbers?</h6>
11701181 results of arithmetic operations can be misleading.
11711182 </ p >
11721183 < pre >
1184+ // Java's BigDecimal
11731185x = new BigDecimal("1.0")
11741186y = new BigDecimal("1.1000")
11751187z = x.add(y) // 2.1000
0 commit comments