Skip to content

Commit 27dac46

Browse files
committed
Update API document
1 parent d54f97e commit 27dac46

File tree

3 files changed

+31
-19
lines changed

3 files changed

+31
-19
lines changed

big.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -730,13 +730,13 @@
730730

731731

732732
/*
733-
* Return a new Big whose value is the value of this Big rounded to a maximum of dp decimal
734-
* places using rounding mode rm.
733+
* Return a new Big whose value is the value of this Big rounded using rounding mode rm
734+
* to a maximum of dp decimal places, or, if dp is negative, to an integer which is a
735+
* multiple of 10**-dp.
735736
* If dp is not specified, round to 0 decimal places.
736-
* If dp is negative, round to a multiple of 10**abs(dp).
737737
* If rm is not specified, use Big.RM.
738738
*
739-
* dp? {number} Integer, 0 to MAX_DP inclusive.
739+
* dp? {number} Integer, -MAX_DP to MAX_DP inclusive.
740740
* rm? 0, 1, 2 or 3 (ROUND_DOWN, ROUND_HALF_UP, ROUND_HALF_EVEN, ROUND_UP)
741741
*/
742742
P.round = function (dp, rm) {

big.mjs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -727,13 +727,13 @@ P.pow = function (n) {
727727

728728

729729
/*
730-
* Return a new Big whose value is the value of this Big rounded to a maximum of dp decimal
731-
* places using rounding mode rm.
730+
* Return a new Big whose value is the value of this Big rounded using rounding mode rm
731+
* to a maximum of dp decimal places, or, if dp is negative, to an integer which is a
732+
* multiple of 10**-dp.
732733
* If dp is not specified, round to 0 decimal places.
733-
* If dp is negative, round to a multiple of 10**abs(dp).
734734
* If rm is not specified, use Big.RM.
735735
*
736-
* dp? {number} Integer, 0 to MAX_DP inclusive.
736+
* dp? {number} Integer, -MAX_DP to MAX_DP inclusive.
737737
* rm? 0, 1, 2 or 3 (ROUND_DOWN, ROUND_HALF_UP, ROUND_HALF_EVEN, ROUND_UP)
738738
*/
739739
P.round = function (dp, rm) {

doc/bigAPI.html

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -566,35 +566,44 @@ <h5 id="round">
566566
<i>&rArr; 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+
588594
x = 123.45
589595
Math.round(x) // 123
596+
590597
y = new Big(x)
591598
y.round() // '123'
592599
y.round(2) // '123.45'
593600
y.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'
598607
y // '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>
10711080
x = new Big('987.654321')
10721081
len = x.c.length // 9
10731082
if (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();
10741085
x // 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
11731185
x = new BigDecimal("1.0")
11741186
y = new BigDecimal("1.1000")
11751187
z = x.add(y) // 2.1000

0 commit comments

Comments
 (0)