Lines Matching full:decimal
7 <title>decimal.js API</title>
64 <ul><li><a href="#decimal"><strong>Decimal</strong></a></li></ul>
216 <h1>decimal<span id='js'>.js</span></h1>
218 <p>An arbitrary-precision Decimal type for JavaScript.</p>
219 <p><a href='https://github.com/MikeMcl/decimal.js'>Hosted on GitHub</a>.</p>
224 See the <a href='https://github.com/MikeMcl/decimal.js'>README</a> on GitHub for a quick-start
233 <a href='#decimal'><code>Decimal</code></a>, the constructor of Decimal instances.
237 If necessary, multiple Decimal constructors can be created, each with their own independent
238 configuration, e.g. precision and range, which applies to all Decimal instances created from
244 A new Decimal constructor is created by calling the <code><a href='#Dclone'>clone</a></code>
245 method of an already existing Decimal constructor.
253 <h5 id="decimal">
254 Decimal<code class='inset'>Decimal(value) <i>⇒ Decimal</i></code>
257 <dt><code>value</code>: <i>number|string|Decimal</i></dt>
271 As well as in decimal, a string <code>value</code> may be expressed in binary, hexadecimal
277 Both decimal and non-decimal string values may use exponential (floating-point), as well as
282 for decimal values, and <code>p</code> or <code>P</code> defines a power-of-two exponent for
283 non-decimal values, i.e. binary, hexadecimal or octal.
286 <p>Returns a new Decimal object instance.</p>
289 x = new Decimal(9) // '9'
290 y = new Decimal(x) // '9'
292 new Decimal('5032485723458348569331745.33434346346912144534543')
293 new Decimal('4.321e+4') // '43210'
294 new Decimal('-735.0918e-430') // '-7.350918e-428'
295 new Decimal('5.6700000') // '5.67'
296 new Decimal(Infinity) // 'Infinity'
297 new Decimal(NaN) // 'NaN'
298 new Decimal('.5') // '0.5'
299 new Decimal('-0b10110100.1') // '-180.5'
300 new Decimal('0xff.8') // '255.5'
302 new Decimal(0.046875) // '0.046875'
303 new Decimal('0.046875000000') // '0.046875'
304 new Decimal('0.046_875_000_000') // '0.046875'
306 new Decimal(4.6875e-2) // '0.046875'
307 new Decimal('468.75e-4') // '0.046875'
309 new Decimal('0b0.000011') // '0.046875'
310 new Decimal('0o0.03') // '0.046875'
311 new Decimal('0x0.0c') // '0.046875'
313 new Decimal('0b1.1p-5') // '0.046875'
314 new Decimal('0o1.4p-5') // '0.046875'
315 new Decimal('0x1.8p-5') // '0.046875'</pre>
320 <p>The methods of a Decimal constructor.</p>
324 <h5 id="Dabs">abs<code class='inset'>.abs(x) <i>⇒ Decimal</i></code></h5>
325 <p><code>x</code>: <i>number|string|Decimal</i></p>
327 <pre>a = Decimal.abs(x)
328 b = new Decimal(x).abs()
333 <h5 id="Dacos">acos<code class='inset'>.acos(x) <i>⇒ Decimal</i></code></h5>
334 <p><code>x</code>: <i>number|string|Decimal</i></p>
336 <pre>a = Decimal.acos(x)
337 b = new Decimal(x).acos()
342 <h5 id="Dacosh">acosh<code class='inset'>.acosh(x) <i>⇒ Decimal</i></code></h5>
343 <p><code>x</code>: <i>number|string|Decimal</i></p>
345 <pre>a = Decimal.acosh(x)
346 b = new Decimal(x).acosh()
351 <h5 id="Dadd">add<code class='inset'>.add(x, y) <i>⇒ Decimal</i></code></h5>
353 <code>x</code>: <i>number|string|Decimal</i><br />
354 <code>y</code>: <i>number|string|Decimal</i>
357 <pre>a = Decimal.add(x, y)
358 b = new Decimal(x).plus(y)
363 <h5 id="Dasin">asin<code class='inset'>.asin(x) <i>⇒ Decimal</i></code></h5>
364 <p><code>x</code>: <i>number|string|Decimal</i></p>
366 <pre>a = Decimal.asin(x)
367 b = new Decimal(x).asin()
372 <h5 id="Dasinh">asinh<code class='inset'>.asinh(x) <i>⇒ Decimal</i></code></h5>
373 <p><code>x</code>: <i>number|string|Decimal</i></p>
375 <pre>a = Decimal.asinh(x)
376 b = new Decimal(x).asinh()
381 <h5 id="Datan">atan<code class='inset'>.atan(x) <i>⇒ Decimal</i></code></h5>
382 <p><code>x</code>: <i>number|string|Decimal</i></p>
384 <pre>a = Decimal.atan(x)
385 b = new Decimal(x).atan()
390 <h5 id="Datanh">atanh<code class='inset'>.atanh(x) <i>⇒ Decimal</i></code></h5>
391 <p><code>x</code>: <i>number|string|Decimal</i></p>
393 <pre>a = Decimal.atanh(x)
394 b = new Decimal(x).atanh()
399 <h5 id="Datan2">atan2<code class='inset'>.atan2(y, x) <i>⇒ Decimal</i></code></h5>
401 <code>y</code>: <i>number|string|Decimal</i><br />
402 <code>x</code>: <i>number|string|Decimal</i>
405 Returns a new Decimal whose value is the inverse tangent in radians of the quotient of
421 <pre>r = Decimal.atan2(y, x)</pre>
425 <h5 id="Dcbrt">cbrt<code class='inset'>.cbrt(x) <i>⇒ Decimal</i></code></h5>
426 <p><code>x</code>: <i>number|string|Decimal</i></p>
428 <pre>a = Decimal.cbrt(x)
429 b = new Decimal(x).cbrt()
434 <h5 id="Dceil">ceil<code class='inset'>.ceil(x) <i>⇒ Decimal</i></code></h5>
435 <p><code>x</code>: <i>number|string|Decimal</i></p>
437 <pre>a = Decimal.ceil(x)
438 b = new Decimal(x).ceil()
443 <h5 id="Dclamp">clamp<code class='inset'>.clamp(min, max) <i>⇒ Decimal</i></code></h5>
445 <code>min</code>: <i>number|string|Decimal</i><br />
446 <code>max</code>: <i>number|string|Decimal</i>
449 <pre>Decimal.clamp(10.1, 0, 10) // '10'</pre>
455 <code class='inset'>.clone([object]) <i>⇒ Decimal constructor</i></code>
459 Returns a new independent Decimal constructor with configuration settings as described by
461 settings as <code>this</code> Decimal constructor if <code>object</code> is omitted.
463 <pre>Decimal.set({ precision: 5 })
464 Decimal9 = Decimal.clone({ precision: 9 })
466 a = new Decimal(1)
472 // Decimal9 = Decimal.clone({ precision: 9 }) is equivalent to:
473 Decimal9 = Decimal.clone()
480 D1 = Decimal.clone({ defaults: true })
483 D2 = Decimal.clone({ defaults: true, precision: 50 })</pre>
485 It is not inefficient in terms of memory usage to use multiple Decimal constructors as
490 <h5 id="Dcos">cos<code class='inset'>.cos(x) <i>⇒ Decimal</i></code></h5>
491 <p><code>x</code>: <i>number|string|Decimal</i></p>
493 <pre>a = Decimal.cos(x)
494 b = new Decimal(x).cos()
499 <h5 id="Dcosh">cosh<code class='inset'>.cosh(x) <i>⇒ Decimal</i></code></h5>
500 <p><code>x</code>: <i>number|string|Decimal</i></p>
502 <pre>a = Decimal.cosh(x)
503 b = new Decimal(x).cosh()
508 <h5 id="Ddiv">div<code class='inset'>.div(x, y) <i>⇒ Decimal</i></code></h5>
510 <code>x</code>: <i>number|string|Decimal</i><br />
511 <code>y</code>: <i>number|string|Decimal</i>
514 <pre>a = Decimal.div(x, y)
515 b = new Decimal(x).div(y)
520 <h5 id="Dexp">exp<code class='inset'>.exp(x) <i>⇒ Decimal</i></code></h5>
521 <p><code>x</code>: <i>number|string|Decimal</i></p>
523 <pre>a = Decimal.exp(x)
524 b = new Decimal(x).exp()
529 <h5 id="Dfloor">floor<code class='inset'>.floor(x) <i>⇒ Decimal</i></code></h5>
530 <p><code>x</code>: <i>number|string|Decimal</i></p>
532 <pre>a = Decimal.floor(x)
533 b = new Decimal(x).floor()
539 hypot<code class='inset'>.hypot([x [, y, ...]]) <i>⇒ Decimal</i></code>
542 <code>x</code>: <i>number|string|Decimal</i><br />
543 <code>y</code>: <i>number|string|Decimal</i>
546 Returns a new Decimal whose value is the square root of the sum of the squares of the
550 <pre>r = Decimal.hypot(x, y)</pre>
554 <h5 id="Dln">ln<code class='inset'>.ln(x) <i>⇒ Decimal</i></code></h5>
555 <p><code>x</code>: <i>number|string|Decimal</i></p>
557 <pre>a = Decimal.ln(x)
558 b = new Decimal(x).ln()
568 Returns <code>true</code> if <code>object</code> is a Decimal instance (where Decimal is any
569 Decimal constructor), or <code>false</code> if it is not.
571 <pre>a = new Decimal(1)
573 a instanceof Decimal // true
574 Decimal.isDecimal(a) // true
575 Decimal.isDecimal(b) // false</pre>
579 <h5 id="Dlog">log<code class='inset'>.log(x [, base]) <i>⇒ Decimal</i></code></h5>
581 <code>x</code>: <i>number|string|Decimal</i><br />
582 <code>base</code>: <i>number|string|Decimal</i>
589 <pre>a = Decimal.log(x, y)
590 b = new Decimal(x).log(y)
595 <h5 id="Dlog2">log2<code class='inset'>.log2(x) <i>⇒ Decimal</i></code></h5>
596 <p><code>x</code>: <i>number|string|Decimal</i></p>
598 Returns a new Decimal whose value is the base <code>2</code> logarithm of <code>x</code>,
602 <pre>r = Decimal.log2(x)</pre>
606 <h5 id="Dlog10">log10<code class='inset'>.log10(x) <i>⇒ Decimal</i></code></h5>
607 <p><code>x</code>: <i>number|string|Decimal</i></p>
609 Returns a new Decimal whose value is the base <code>10</code> logarithm of <code>x</code>,
613 <pre>r = Decimal.log10(x)</pre>
618 max<code class='inset'>.max(x [, y, ...]) <i>⇒ Decimal</i></code>
621 <code>x</code>: <i>number|string|Decimal</i><br />
622 <code>y</code>: <i>number|string|Decimal</i>
624 <p>Returns a new Decimal whose value is the maximum of the <code>arguments</code>.</p>
625 <pre>r = Decimal.max(x, y, z)</pre>
630 min<code class='inset'>.min(x [, y, ...]) <i>⇒ Decimal</i></code>
633 <code>x</code>: <i>number|string|Decimal</i><br />
634 <code>y</code>: <i>number|string|Decimal</i>
636 <p>Returns a new Decimal whose value is the minimum of the <code>arguments</code>.</p>
637 <pre>r = Decimal.min(x, y, z)</pre>
641 <h5 id="Dmod">mod<code class='inset'>.mod(x, y) <i>⇒ Decimal</i></code></h5>
643 <code>x</code>: <i>number|string|Decimal</i><br />
644 <code>y</code>: <i>number|string|Decimal</i>
647 <pre>a = Decimal.mod(x, y)
648 b = new Decimal(x).mod(y)
653 <h5 id="Dmul">mul<code class='inset'>.mul(x, y) <i>⇒ Decimal</i></code></h5>
655 <code>x</code>: <i>number|string|Decimal</i><br />
656 <code>y</code>: <i>number|string|Decimal</i>
659 <pre>a = Decimal.mul(x, y)
660 b = new Decimal(x).mul(y)
666 noConflict<code class='inset'>.noConflict() <i>⇒ Decimal constructor</i></code>
670 Reverts the <code>Decimal</code> variable to the value it had before this library was loaded
671 and returns a reference to the original Decimal constructor so it can be assigned to a
675 <script> Decimal = 1 </script>
676 <script src='/path/to/decimal.js'></script>
678 a = new Decimal(2) // '2'
679 D = Decimal.noConflict()
680 Decimal // 1
686 <h5 id="Dpow">pow<code class='inset'>.pow(base, exponent) <i>⇒ Decimal</i></code></h5>
688 <code>base</code>: <i>number|string|Decimal</i><br />
689 <code>exponent</code>: <i>number|string|Decimal</i>
692 <pre>a = Decimal.pow(x, y)
693 b = new Decimal(x).pow(y)
699 random<code class='inset'>.random([dp]) <i>⇒ Decimal</i></code>
703 Returns a new Decimal with a pseudo-random value equal to or greater than <code>0</code> and
707 The return value will have <code>dp</code> decimal places (or less if trailing zeros are
708 produced). If <code>dp</code> is omitted then the number of decimal places will
712 If the value of <code>this</code> Decimal constructor's
723 If the value of <code>this</code> Decimal constructor's
729 If one of the <code>crypto</code> methods is used, the value of the returned Decimal should be
732 <pre>Decimal.set({ precision: 10 })
733 Decimal.random() // '0.4117936847'
734 Decimal.random(20) // '0.78193327636914089009'</pre>
737 <h5 id="Dround">round<code class='inset'>.round(x) <i>⇒ Decimal</i></code></h5>
738 <p><code>x</code>: <i>number|string|Decimal</i></p>
740 <pre>a = Decimal.round(x)
741 b = new Decimal(x).round()
746 <h5 id="Dset">set<code class='inset'>.set(object) <i>⇒ Decimal constructor</i></code></h5>
749 Configures the 'global' settings for <code>this</code> particular Decimal constructor, i.e.
750 the settings which apply to operations performed on the Decimal instances created by it.
752 <p>Returns <code>this</code> Decimal constructor.</p>
760 equivalently-named properties of <code>this</code> Decimal constructor.
769 Decimal.set({
781 Decimal.set({ defaults: true })
784 Decimal.set({ precision: 50, defaults: true })</pre>
786 The properties of a Decimal constructor can also be set by direct assignment, but that will
790 <pre>Decimal.precision = 40</pre>
795 <p><code>x</code>: <i>number|string|Decimal</i></p>
819 <pre>r = Decimal.sign(x)</pre>
823 <h5 id="Dsin">sin<code class='inset'>.sin(x) <i>⇒ Decimal</i></code></h5>
824 <p><code>x</code>: <i>number|string|Decimal</i></p>
826 <pre>a = Decimal.sin(x)
827 b = new Decimal(x).sin()
832 <h5 id="Dsinh">sinh<code class='inset'>.sinh(x) <i>⇒ Decimal</i></code></h5>
833 <p><code>x</code>: <i>number|string|Decimal</i></p>
835 <pre>a = Decimal.sinh(x)
836 b = new Decimal(x).sinh()
841 <h5 id="Dsqrt">sqrt<code class='inset'>.sqrt(x) <i>⇒ Decimal</i></code></h5>
842 <p><code>x</code>: <i>number|string|Decimal</i></p>
844 <pre>a = Decimal.sqrt(x)
845 b = new Decimal(x).sqrt()
850 <h5 id="Dsub">sub<code class='inset'>.sub(x, y) <i>⇒ Decimal</i></code></h5>
852 <code>x</code>: <i>number|string|Decimal</i><br />
853 <code>y</code>: <i>number|string|Decimal</i>
856 <pre>a = Decimal.sub(x, y)
857 b = new Decimal(x).sub(y)
862 <h5 id="Dsum">sum<code class='inset'>.sum(x [, y, ...]) <i>⇒ Decimal</i></code></h5>
864 <code>x</code>: <i>number|string|Decimal</i><br />
865 <code>y</code>: <i>number|string|Decimal</i>
868 Returns a new Decimal whose value is the sum of the <code>arguments</code>,
876 z = new Decimal(-11)
877 Decimal.sum(x, y, z) // '10'</pre>
881 <h5 id="Dtan">tan<code class='inset'>.tan(x) <i>⇒ Decimal</i></code></h5>
882 <p><code>x</code>: <i>number|string|Decimal</i></p>
884 <pre>a = Decimal.tan(x)
885 b = new Decimal(x).tan()
890 <h5 id="Dtanh">tanh<code class='inset'>.tanh(x) <i>⇒ Decimal</i></code></h5>
891 <p><code>x</code>: <i>number|string|Decimal</i></p>
893 <pre>a = Decimal.tanh(x)
894 b = new Decimal(x).tanh()
899 <h5 id="Dtrunc">trunc<code class='inset'>.trunc(x) <i>⇒ Decimal</i></code></h5>
900 <p><code>x</code>: <i>number|string|Decimal</i></p>
902 <pre>a = Decimal.trunc(x)
903 b = new Decimal(x).trunc()
910 <p>The properties of a Decimal constructor.</p>
928 <pre>Decimal.set({ precision: 0 })
931 Decimal.precision = 0
943 All functions which return a Decimal will round the return value to <code>precision</code>
944 significant digits except <a href='#decimal'><code>Decimal</code></a>,
958 <pre>Decimal.set({ precision: 5 })
959 Decimal.precision // 5</pre>
986 <pre>Decimal.set({ rounding: Decimal.ROUND_UP })
987 Decimal.set({ rounding: 0 }) // equivalent
988 Decimal.rounding // 0</pre>
1001 If the <code>Decimal</code> to be returned by a calculation would have an exponent lower than
1002 <code>minE</code> then the value of that <code>Decimal</code> becomes zero.
1006 <pre>Decimal.set({ minE: -500 })
1007 Decimal.minE // -500
1008 new Decimal('1e-500') // '1e-500'
1009 new Decimal('9.9e-501') // '0'
1011 Decimal.set({ minE: -3 })
1012 new Decimal(0.001) // '0.001' e is -3
1013 new Decimal(0.0001) // '0' e is -4</pre>
1015 The smallest possible magnitude of a non-zero Decimal is <code>1e-9000000000000000</code>
1030 If the <code>Decimal</code> to be returned by a calculation would have an exponent higher than
1031 <code>maxE</code> then the value of that <code>Decimal</code> becomes <code>Infinity</code>.
1035 <pre>Decimal.set({ maxE: 500 })
1036 Decimal.maxE // 500
1037 new Decimal('9.999e500') // '9.999e+500'
1038 new Decimal('1e501') // 'Infinity'
1040 Decimal.set({ maxE: 4 })
1041 new Decimal(99999) // '99999' e is 4
1042 new Decimal(100000) // 'Infinity'</pre>
1044 The largest possible magnitude of a finite Decimal is <code>9.999...e+9000000000000000</code>
1058 <pre>Decimal.set({ toExpNeg: -7 })
1059 Decimal.toExpNeg // -7
1060 new Decimal(0.00000123) // '0.00000123' e is -6
1061 new Decimal(0.000000123) // '1.23e-7'
1064 Decimal.set({ toExpNeg: 0 })</pre>
1087 <pre>Decimal.set({ toExpPos: 2 })
1088 Decimal.toExpPos // 2
1089 new Decimal(12.3) // '12.3' e is 1
1090 new Decimal(123) // '1.23e+2'
1093 Decimal.set({ toExpPos: 0 })</pre>
1158 The rounding/modulo modes are available as enumerated properties of the Decimal constructor.
1160 <pre>Decimal.set({ modulo: Decimal.EUCLID })
1161 Decimal.set({ modulo: 9 }) // equivalent
1162 Decimal.modulo // 9</pre>
1179 Decimal.crypto // false
1180 Decimal.set({ crypto: true })
1181 Decimal.crypto // true</pre>
1187 The library's enumerated rounding modes are stored as properties of the Decimal constructor.
1224 <pre>Decimal.set({ rounding: Decimal.ROUND_CEIL })
1225 Decimal.set({ rounding: 2 }) // equivalent
1226 Decimal.rounding // 2</pre>
1234 <p>The methods inherited by a Decimal instance from its constructor's prototype object.</p>
1235 <p>A Decimal instance is immutable in the sense that it is not changed by its methods.</p>
1236 <p>Methods that return a Decimal can be chained:</p>
1237 <pre>x = new Decimal(2).times('999.999999999999999').dividedBy(4).ceil()</pre>
1250 <h5 id="abs">absoluteValue<code class='inset'>.abs() <i>⇒ Decimal</i></code></h5>
1252 Returns a new Decimal whose value is the absolute value, i.e. the magnitude, of the value of
1253 this Decimal.
1260 x = new Decimal(-0.8)
1266 <h5 id="ceil">ceil<code class='inset'>.ceil() <i>⇒ Decimal</i></code></h5>
1268 Returns a new Decimal whose value is the value of this Decimal rounded to a whole number in
1276 x = new Decimal(1.3)
1278 y = new Decimal(-1.8)
1283 <h5 id="clamp">clampedTo<code class='inset'>.clamp(min, max) <i>⇒ Decimal</i></code></h5>
1285 <code>min</code>: <i>number|string|Decimal</i><br />
1286 <code>max</code>: <i>number|string|Decimal</i>
1289 Returns a new Decimal whose value is the value of this Decimal clamped to the range
1297 x = new Decimal(5)
1298 min = new Decimal(100)
1299 max = new Decimal(Infinity)
1306 <p><code>x</code>: <i>number|string|Decimal</i></p>
1311 <td>if the value of this Decimal is greater than the value of <code>x</code></td>
1315 <td>if the value of this Decimal is less than the value of <code>x</code></td>
1319 <td>if this Decimal and <code>x</code> have the same value</td>
1323 <td>if the value of either this Decimal or <code>x</code> is <code>NaN</code> </td>
1327 x = new Decimal(Infinity)
1328 y = new Decimal(5)
1335 <h5 id="cos">cosine<code class='inset'>.cos() <i>⇒ Decimal</i></code></h5>
1337 Returns a new Decimal whose value is the cosine of the value in radians of this Decimal,
1347 x = new Decimal(0.25)
1349 y = new Decimal(-0.25)
1354 <h5 id="cbrt">cubeRoot<code class='inset'>.cbrt() <i>⇒ Decimal</i></code></h5>
1356 Returns a new Decimal whose value is the cube root of this Decimal, rounded to
1365 x = new Decimal(125)
1367 y = new Decimal(3)
1374 Returns the number of decimal places, i.e. the number of digits after the decimal point, of
1375 the value of this Decimal.
1378 x = new Decimal(1.234)
1380 y = new Decimal(987.654321)
1385 <h5 id="div">dividedBy<code class='inset'>.div(x) <i>⇒ Decimal</i></code></h5>
1386 <p><code>x</code>: <i>number|string|Decimal</i></p>
1388 Returns a new Decimal whose value is the value of this Decimal divided by <code>x</code>,
1393 x = new Decimal(355)
1394 y = new Decimal(113)
1401 dividedToIntegerBy<code class='inset'>.divToInt(x) <i>⇒ Decimal</i></code>
1403 <p><code>x</code>: <i>number|string|Decimal</i></p>
1405 Return a new Decimal whose value is the integer part of dividing this Decimal by
1410 x = new Decimal(5)
1411 y = new Decimal(3)
1418 <p><code>x</code>: <i>number|string|Decimal</i></p>
1420 Returns <code>true</code> if the value of this Decimal equals the value of <code>x</code>,
1427 x = new Decimal(0)
1429 new Decimal(-0).eq(x) // true ( -0 === 0 )
1431 y = new Decimal(NaN)
1436 <h5 id="floor">floor<code class='inset'>.floor() <i>⇒ Decimal</i></code></h5>
1438 Returns a new Decimal whose value is the value of this Decimal rounded to a whole number in
1446 x = new Decimal(1.8)
1448 y = new Decimal(-1.3)
1454 <p><code>x</code>: <i>number|string|Decimal</i></p>
1456 Returns <code>true</code> if the value of this Decimal is greater than the value of
1462 x = new Decimal(0.1)
1463 x.greaterThan(Decimal(0.3).minus(0.2)) // false
1464 new Decimal(0).gt(x) // false</pre>
1471 <p><code>x</code>: <i>number|string|Decimal</i></p>
1473 Returns <code>true</code> if the value of this Decimal is greater than or equal to the value
1479 x = new Decimal(0.3).minus(0.2)
1481 new Decimal(1).gte(x) // true</pre>
1485 <h5 id="cosh">hyperbolicCosine<code class='inset'>.cosh() <i>⇒ Decimal</i></code></h5>
1487 Returns a new Decimal whose value is the hyperbolic cosine of the value in radians of this
1488 Decimal, rounded to <a href='#precision'><code>precision</code></a> significant digits using
1497 x = new Decimal(1)
1499 y = new Decimal(0.5)
1504 <h5 id="sinh">hyperbolicSine<code class='inset'>.sinh() <i>⇒ Decimal</i></code></h5>
1506 Returns a new Decimal whose value is the hyperbolic sine of the value in radians of this
1507 Decimal, rounded to <a href='#precision'><code>precision</code></a> significant digits using
1516 x = new Decimal(1)
1518 y = new Decimal(0.5)
1523 <h5 id="tanh">hyperbolicTangent<code class='inset'>.tanh() <i>⇒ Decimal</i></code></h5>
1525 Returns a new Decimal whose value is the hyperbolic tangent of the value in radians of this
1526 Decimal, rounded to <a href='#precision'><code>precision</code></a> significant digits using
1535 x = new Decimal(1)
1537 y = new Decimal(0.5)
1542 <h5 id="acos">inverseCosine<code class='inset'>.acos() <i>⇒ Decimal</i></code></h5>
1544 Returns a new Decimal whose value is the inverse cosine in radians of the value of this
1545 Decimal, rounded to <a href='#precision'><code>precision</code></a> significant digits using
1554 x = new Decimal(0)
1556 y = new Decimal(0.5)
1562 inverseHyperbolicCosine<code class='inset'>.acosh() <i>⇒ Decimal</i></code>
1565 Returns a new Decimal whose value is the inverse hyperbolic cosine in radians of the value of
1566 this Decimal, rounded to <a href='#precision'><code>precision</code></a> significant
1575 x = new Decimal(5)
1577 y = new Decimal(50)
1583 inverseHyperbolicSine<code class='inset'>.asinh() <i>⇒ Decimal</i></code>
1586 Returns a new Decimal whose value is the inverse hyperbolic sine in radians of the value of
1587 this Decimal, rounded to <a href='#precision'><code>precision</code></a> significant digits
1596 x = new Decimal(5)
1598 y = new Decimal(50)
1604 inverseHyperbolicTangent<code class='inset'>.atanh() <i>⇒ Decimal</i></code>
1607 Returns a new Decimal whose value is the inverse hyperbolic tangent in radians of the value of
1608 this Decimal, rounded to <a href='#precision'><code>precision</code></a> significant
1617 x = new Decimal(0.5)
1619 y = new Decimal(0.75)
1624 <h5 id="asin">inverseSine<code class='inset'>.asin() <i>⇒ Decimal</i></code></h5>
1626 Returns a new Decimal whose value is the inverse sine in radians of the value of this Decimal,
1636 x = new Decimal(0.5)
1638 y = new Decimal(0.75)
1643 <h5 id="atan">inverseTangent<code class='inset'>.atan() <i>⇒ Decimal</i></code></h5>
1645 Returns a new Decimal whose value is the inverse tangent in radians of the value of this
1646 Decimal, rounded to <a href='#precision'><code>precision</code></a> significant digits using
1655 x = new Decimal(0.5)
1657 y = new Decimal(0.75)
1664 Returns <code>true</code> if the value of this Decimal is a finite number, otherwise returns
1666 The only possible non-finite values of a Decimal are <code>NaN</code>, <code>Infinity</code>
1670 x = new Decimal(1)
1672 y = new Decimal(Infinity)
1679 Returns <code>true</code> if the value of this Decimal is a whole number, otherwise returns
1683 x = new Decimal(1)
1685 y = new Decimal(123.456)
1692 Returns <code>true</code> if the value of this Decimal is <code>NaN</code>, otherwise returns
1696 x = new Decimal(NaN)
1698 y = new Decimal('Infinity')
1705 Returns <code>true</code> if the value of this Decimal is negative, otherwise returns
1709 x = new Decimal(-0)
1711 y = new Decimal(2)
1715 new Decimal(0).valueOf() // '0'
1716 new Decimal(0).isNegative() // false
1717 new Decimal(0).negated().valueOf() // '-0'
1718 new Decimal(0).negated().isNegative() // true
1719 new Decimal(-0).isNegative() // true
1726 Returns <code>true</code> if the value of this Decimal is positive, otherwise returns
1730 x = new Decimal(0)
1732 y = new Decimal(-2)
1739 Returns <code>true</code> if the value of this Decimal is zero or minus zero, otherwise
1743 x = new Decimal(-0)
1745 y = new Decimal(Infinity)
1751 <p><code>x</code>: <i>number|string|Decimal</i></p>
1753 Returns <code>true</code> if the value of this Decimal is less than the value of
1759 x = new Decimal(0.3).minus(0.2)
1761 new Decimal(0).lt(x) // true</pre>
1766 <p><code>x</code>: <i>number|string|Decimal</i></p>
1768 Returns <code>true</code> if the value of this Decimal is less than or equal to the value of
1774 x = new Decimal(0.1)
1775 x.lessThanOrEqualTo(Decimal(0.3).minus(0.2)) // true
1776 new Decimal(-1).lte(x) // true</pre>
1780 <h5 id="log">logarithm<code class='inset'>.log(x) <i>⇒ Decimal</i></code></h5>
1781 <p><code>x</code>: <i>number|string|Decimal</i></p>
1783 Returns a new Decimal whose value is the base <code>x</code> logarithm of the value of this
1784 Decimal, rounded to <a href='#precision'><code>precision</code></a> significant digits using
1788 If <code>x</code> is omitted, the base 10 logarithm of the value of this Decimal will be
1792 x = new Decimal(1000)
1794 y = new Decimal(256)
1812 <h5 id="sub">minus<code class='inset'>.minus(x) <i>⇒ Decimal</i></code></h5>
1813 <p><code>x</code>: <i>number|string|Decimal</i></p>
1815 Returns a new Decimal whose value is the value of this Decimal minus <code>x</code>, rounded
1821 x = new Decimal(0.3)
1826 <h5 id="mod">modulo<code class='inset'>.mod(x) <i>⇒ Decimal</i></code></h5>
1827 <p><code>x</code>: <i>number|string|Decimal</i></p>
1829 Returns a new Decimal whose value is the value of this Decimal modulo <code>x</code>,
1835 <a href='#modulo'><code>modulo</code></a> property of this Decimal's constructor. If it is
1836 <code>1</code> (default value), the result will have the same sign as this Decimal, and it
1845 x = new Decimal(1)
1848 y = new Decimal(8)
1849 z = new Decimal(-3)
1850 Decimal.modulo = 1
1852 Decimal.modulo = 3
1857 <h5 id="exp">naturalExponential<code class='inset'>.exp() <i>⇒ Decimal</i></code></h5>
1859 Returns a new Decimal whose value is the base <code>e</code> (Euler's number, the base of the
1860 natural logarithm) exponential of the value of this Decimal, rounded to
1868 x = new Decimal(1)
1870 y = new Decimal(2)
1881 <h5 id="ln">naturalLogarithm<code class='inset'>.ln() <i>⇒ Decimal</i></code></h5>
1883 Returns a new Decimal whose value is the natural logarithm of the value of this Decimal,
1892 x = new Decimal(10)
1894 y = new Decimal('1.23e+30')
1916 <h5 id="neg">negated<code class='inset'>.neg() <i>⇒ Decimal</i></code></h5>
1918 Returns a new Decimal whose value is the value of this Decimal negated, i.e. multiplied by
1926 x = new Decimal(1.8)
1928 y = new Decimal(-1.3)
1933 <h5 id="add">plus<code class='inset'>.plus(x) <i>⇒ Decimal</i></code></h5>
1934 <p><code>x</code>: <i>number|string|Decimal</i></p>
1936 Returns a new Decimal whose value is the value of this Decimal plus <code>x</code>, rounded to
1942 x = new Decimal(0.1)
1944 new Decimal(0.7).plus(x).plus(y) // '1.1'</pre>
1949 <p>Returns the number of significant digits of the value of this Decimal.</p>
1955 x = new Decimal(1.234)
1957 y = new Decimal(987000)
1963 <h5 id="round">round<code class='inset'>.round() <i>⇒ Decimal</i></code></h5>
1965 Returns a new Decimal whose value is the value of this Decimal rounded to a whole number using
1973 Decimal.set({ rounding: 4 })
1977 Decimal.rounding = Decimal.ROUND_DOWN
1983 <h5 id="sin">sine<code class='inset'>.sin() <i>⇒ Decimal</i></code></h5>
1985 Returns a new Decimal whose value is the sine of the value in radians of this Decimal,
1995 x = new Decimal(0.5)
1997 y = new Decimal(0.75)
2002 <h5 id="sqrt">squareRoot<code class='inset'>.sqrt() <i>⇒ Decimal</i></code></h5>
2004 Returns a new Decimal whose value is the square root of this Decimal, rounded to
2017 x = new Decimal(16)
2019 y = new Decimal(3)
2025 <h5 id="tan">tangent<code class='inset'>.tan() <i>⇒ Decimal</i></code></h5>
2027 Returns a new Decimal whose value is the tangent of the value in radians of this Decimal,
2037 x = new Decimal(0.5)
2039 y = new Decimal(0.75)
2044 <h5 id="mul">times<code class='inset'>.times(x) <i>⇒ Decimal</i></code></h5>
2045 <p><code>x</code>: <i>number|string|Decimal</i></p>
2047 Returns a new Decimal whose value is the value of this Decimal times <code>x</code>,
2053 x = new Decimal(0.6)
2055 new Decimal('7e+500').times(y) // '1.26e+501'</pre>
2067 Returns a string representing the value of this Decimal in binary, rounded to <code>sd</code>
2083 x = new Decimal(256)
2090 toDecimalPlaces<code class='inset'>.toDP([dp [, rm]]) <i>⇒ Decimal</i></code>
2097 Returns a new Decimal whose value is the value of this Decimal rounded to <code>dp</code>
2098 decimal places using rounding mode <code>rm</code>.
2101 If <code>dp</code> is omitted, the return value will have the same value as this Decimal.
2109 x = new Decimal(12.34567)
2111 x.toDecimalPlaces(1, Decimal.ROUND_UP) // '12.4'
2113 y = new Decimal(9876.54321)
2116 y.toDP(1, Decimal.ROUND_DOWN) // '9876.5'</pre>
2128 Returns a string representing the value of this Decimal in exponential notation rounded
2129 using rounding mode <code>rm</code> to <code>dp</code> decimal places, i.e with one digit
2130 before the decimal point and <code>dp</code> digits after it.
2133 If the value of this Decimal in exponential notation has fewer than <code>dp</code> fraction
2137 If <code>dp</code> is omitted, the number of digits after the decimal point defaults to the
2147 y = new Decimal(x)
2154 y.toExponential(1, Decimal.ROUND_DOWN) // '4.5e+1'
2168 Returns a string representing the value of this Decimal in normal (fixed-point) notation
2169 rounded to <code>dp</code> decimal places using rounding mode <code>rm</code>.
2172 If the value of this Decimal in normal notation has fewer than <code>dp</code> fraction
2182 is unlike <code>Number.prototype.toFixed</code>, which returns the value to zero decimal
2195 y = new Decimal(x)
2201 y.toFixed(2, Decimal.ROUND_DOWN) // '3.45'
2209 <code class='inset'>.toFraction([max_denominator]) <i>⇒ [Decimal, Decimal]</i></code>
2212 <code>max_denominator</code>: <i>number|string|Decimal</i>: <code>1</code> >= integer <
2216 Returns an array of two Decimals representing the value of this Decimal as a simple fraction
2226 x = new Decimal(1.75)
2229 pi = new Decimal('3.14159265358')
2247 Returns a string representing the value of this Decimal in hexadecimal, rounded to
2263 x = new Decimal(256)
2275 toNearest<code class='inset'>.toNearest(x [, rm]) <i>⇒ Decimal</i></code>
2278 <code>x</code>: <i>number|string|Decimal</i><br />
2282 Returns a new Decimal whose value is the nearest multiple of <code>x</code> in the direction
2284 <code>rm</code> is omitted, to the value of this Decimal.
2287 The return value will always have the same sign as this Decimal, unless either this Decimal
2296 x = new Decimal(1.39)
2299 y = new Decimal(9.499)
2300 y.toNearest(0.5, Decimal.ROUND_UP) // '9.5'
2301 y.toNearest(0.5, Decimal.ROUND_DOWN) // '9'</pre>
2306 <p>Returns the value of this Decimal converted to a primitive number.</p>
2309 a Decimal with the value minus zero will convert to positive zero.
2312 x = new Decimal(456.789)
2316 y = new Decimal('45987349857634085409857349856430985')
2319 z = new Decimal(-0)
2333 Returns a string representing the value of this Decimal in octal, rounded to <code>sd</code>
2349 x = new Decimal(256)
2355 <h5 id="pow">toPower<code class='inset'>.pow(x) <i>⇒ Decimal</i></code></h5>
2356 <p><code>x</code>: <i>number|string|Decimal</i>: integer or non-integer</p>
2358 Returns a new Decimal whose value is the value of this Decimal raised to the power
2368 x = new Decimal(0.7)
2370 new Decimal(3).pow(-2) // '0.11111111111111111111'
2372 new Decimal(1217652.23).pow('98765.489305603941')
2405 Decimal.set({ precision: 20, rounding: 1 })
2406 new Decimal(28).pow('6.166675020000903537297764507632802193308677149')
2426 Returns a string representing the value of this Decimal rounded to <code>sd</code> significant
2444 y = new Decimal(x)
2449 y.toPrecision(2, Decimal.ROUND_UP) // '46'
2450 y.toPrecision(2, Decimal.ROUND_DOWN) // '45'
2457 toSignificantDigits<code class='inset'>.toSD([sd [, rm]]) <i>⇒ Decimal</i></code>
2464 Returns a new Decimal whose value is the value of this Decimal rounded to <code>sd</code>
2477 Decimal.set({ precision: 5, rounding: 4 })
2478 x = new Decimal(9876.54321)
2482 x.toSignificantDigits(6, Decimal.ROUND_UP) // '9876.55'
2490 <p>Returns a string representing the value of this Decimal.</p>
2492 If this Decimal has a positive exponent that is equal to or greater than
2497 x = new Decimal(750000)
2499 Decimal.set({ toExpPos: 5 })
2502 Decimal.set({ precision: 4 })
2503 y = new Decimal('1.23456789')
2508 <h5 id="trunc">truncated<code class='inset'>.trunc() <i>⇒ Decimal</i></code></h5>
2510 Returns a new Decimal whose value is the value of this Decimal truncated to a whole number.
2517 x = new Decimal(123.456)
2519 y = new Decimal(-12.3)
2527 x = new Decimal(-0)
2537 The value of a Decimal is stored in a normalised base <code>10000000</code> floating point
2541 A Decimal instance is an object with three properties:
2575 x = new Decimal(0.123) // '0.123'
2583 z = new Decimal('-123.4567000e+2') // '-12345.67'
2626 y = new Decimal(-0)
2640 <p>To determine if an exception is a Decimal Error:</p>
2665 Decimal.set({precision: 991}).tan(123456789)
2666 Decimal.set({precision: 9}).tan(991_digit_number)</pre>
2682 pi = Decimal.acos(-1)</pre>