{"_id":"@artemcheiv/decimal-js","name":"@artemcheiv/decimal-js","dist-tags":{"latest":"1.0.6"},"versions":{"1.0.6":{"name":"@artemcheiv/decimal-js","description":"An arbitrary-precision Decimal type for JavaScript.","version":"1.0.6","keywords":["arbitrary","precision","arithmetic","big","number","decimal","float","biginteger","bigdecimal","bignumber","bigint","bignum"],"repository":{"type":"git","url":"git+https://github.com/ArtemCheiv/-decimal.git"},"homepage":"https://github.com/ArtemCheiv/-decimal","main":"decimal","module":"decimal.mjs","browser":"decimal.js","exports":{".":{"types":"./decimal.d.ts","import":"./decimal.mjs","require":"./decimal.js"},"./decimal.mjs":"./decimal.mjs","./decimal.js":"./decimal.js","./package.json":"./package.json","./decimal":{"types":"./decimal.d.ts","import":"./decimal.mjs","require":"./decimal.js"}},"author":{"name":"ArtemCheiv","url":"https://github.com/ArtemCheiv"},"license":"MIT","publishConfig":{"access":"public","provenance":true,"registry":"https://registry.npmjs.org/"},"scripts":{"test":"node ./test/test.js"},"types":"decimal.d.ts","gitHead":"811360f8c7f49ea1da8183d73225c6e7cffd5bb8","_id":"@artemcheiv/decimal-js@1.0.6","bugs":{"url":"https://github.com/ArtemCheiv/-decimal/issues"},"_nodeVersion":"22.23.2","_npmVersion":"12.0.2","dist":{"integrity":"sha512-WoBNkG8ee7hpqtucTZDgGQG2BWUAYtiezyuGA091dU1ONurO3sd7L7gu7QaQ0ogcASCTWkFCR3KJ0tjOHJtd2Q==","shasum":"336c0b68d8063bf934e6e2e57b7e9782625f769a","tarball":"https://registry.npmjs.org/@artemcheiv/decimal-js/-/decimal-js-1.0.6.tgz","fileCount":6,"unpackedSize":280252,"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/@artemcheiv%2fdecimal-js@1.0.6","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEYCIQDjfGZmvZZ00qLJUElsIadPHFS1C/lKtyZRcmDHJfgG3QIhAOhbGfTC6UCt/duV/sfsx9jM4BdkOKWHMDv/i+mOD3aL"}]},"_npmUser":{"name":"artemcheiv","email":"ArtemCheiv@proton.me"},"directories":{},"maintainers":[{"name":"artemcheiv","email":"ArtemCheiv@proton.me"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/decimal-js_1.0.6_1787659320927_0.5560687113522473"},"_hasShrinkwrap":false}},"time":{"created":"2026-08-25T12:02:00.735Z","1.0.6":"2026-08-25T12:02:01.073Z","modified":"2026-08-25T12:02:01.490Z"},"maintainers":[{"name":"artemcheiv","email":"ArtemCheiv@proton.me"}],"description":"An arbitrary-precision Decimal type for JavaScript.","homepage":"https://github.com/ArtemCheiv/-decimal","keywords":["arbitrary","precision","arithmetic","big","number","decimal","float","biginteger","bigdecimal","bignumber","bigint","bignum"],"repository":{"type":"git","url":"git+https://github.com/ArtemCheiv/-decimal.git"},"author":{"name":"ArtemCheiv","url":"https://github.com/ArtemCheiv"},"bugs":{"url":"https://github.com/ArtemCheiv/-decimal/issues"},"license":"MIT","readme":"# @artemcheiv/decimal-js\n\nAn arbitrary-precision Decimal type for JavaScript.\n\n**Made by [ArtemCheiv](https://github.com/ArtemCheiv).**\n\n## Features\n\n- Integers and floats\n- Simple but full-featured API\n- Replicates many of the methods of JavaScript's `Number.prototype` and `Math` objects\n- Handles hexadecimal, binary, and octal values\n- Faster, smaller, and easier to use than JavaScript versions of Java's BigDecimal\n- No dependencies\n- Wide platform compatibility: browsers and Node.js\n- Comprehensive [documentation](doc/API.html) and test set\n- Includes a TypeScript declaration file: `decimal.d.ts`\n\nUnlike [bignumber.js](https://github.com/MikeMcl/bignumber.js/), precision here is specified in significant digits rather than decimal places, and all calculations are rounded to that precision (similar to Python's `decimal` module), not only divisions.\n\nThis library also adds trigonometric functions and supports non-integer powers. For a lighter version without trigonometric functions, see [decimal.js-light](https://github.com/MikeMcl/decimal.js-light/).\n\n## Install\n\n```bash\nnpm install @artemcheiv/decimal-js\n```\n\nThe library is the single JavaScript file `decimal.js` or the ES module `decimal.mjs`.\n\n**Browser:**\n\n```html\n<script src=\"path/to/decimal.js\"></script>\n\n<script type=\"module\">\n  import Decimal from './path/to/decimal.mjs';\n</script>\n```\n\n**Node.js:**\n\n```js\nconst Decimal = require('@artemcheiv/decimal-js');\n\nimport Decimal from '@artemcheiv/decimal-js';\n\nimport { Decimal } from '@artemcheiv/decimal-js';\n```\n\n## Use\n\nIn the examples below, semicolons and `toString` calls are omitted. If a commented-out value is in quotes, `toString` has been called on the preceding expression.\n\nThe library exports a single constructor, `Decimal`, which expects a number, string, bigint, or Decimal instance.\n\n```js\nx = new Decimal(123.4567)\ny = new Decimal('123456.7e-3')\nz = new Decimal(x)\nx.equals(y) && y.equals(z) && x.equals(z)        // true\n```\n\nIf a value has more than a few digits, pass a string rather than a number to avoid precision loss.\n\n```js\n// Precision loss from numeric literals with more than 15 significant digits.\nnew Decimal(1.0000000000000001)         // '1'\nnew Decimal(88259496234518.57)          // '88259496234518.56'\nnew Decimal(99999999999999999999)       // '100000000000000000000'\n\n// Precision loss from numeric literals outside the range of Number.\nnew Decimal(2e+308)                     // 'Infinity'\nnew Decimal(1e-324)                     // '0'\n\n// Precision loss from arithmetic with Number values.\nnew Decimal(0.7 + 0.1)                  // '0.7999999999999999'\n```\n\nStrings can contain underscores as separators.\n\n```js\nx = new Decimal('2_147_483_647')\n```\n\nBinary, hexadecimal, and octal strings are accepted when they include the appropriate prefix.\n\n```js\nx = new Decimal('0xff.f')            // '255.9375'\ny = new Decimal('0b10101100')        // '172'\nz = x.plus(y)                        // '427.9375'\n\nz.toBinary()                         // '0b110101011.1111'\nz.toBinary(13)                       // '0b1.101010111111p+8'\n```\n\nDecimal instances are immutable: methods return new values and do not change the original.\n\n```js\n0.3 - 0.1                     // 0.19999999999999998\nx = new Decimal(0.3)\nx.minus(0.1)                  // '0.2'\nx                             // '0.3'\n```\n\nMethods that return a Decimal can be chained.\n\n```js\nx.dividedBy(y).plus(z).times(9).floor()\nx.times('1.23456780123456789e+9').plus(9876.5432321).dividedBy('4444562598.111772').ceil()\n```\n\nMany methods have a shorter alias.\n\n```js\nx.squareRoot().dividedBy(y).toPower(3).equals(x.sqrt().div(y).pow(3))     // true\nx.comparedTo(y.modulo(z).negated()) === x.cmp(y.mod(z).neg())             // true\n```\n\nMost methods of JavaScript's `Number.prototype` and `Math` objects are replicated.\n\n```js\nx = new Decimal(255.5)\nx.toExponential(5)                       // '2.55500e+2'\nx.toFixed(5)                             // '255.50000'\nx.toPrecision(5)                         // '255.50'\n\nDecimal.sqrt('6.98372465832e+9823')      // '8.3568682281821340204e+4911'\nDecimal.pow(2, 0.0979843)                // '1.0702770511687781839'\n\nx = new Decimal('0.0000001')\nx.toString()                             // '1e-7'\nx.toFixed()                              // '0.0000001'\n```\n\n`NaN` and `Infinity` are valid Decimal values.\n\n```js\nx = new Decimal(NaN)                                           // 'NaN'\ny = new Decimal(Infinity)                                      // 'Infinity'\nx.isNaN() && !y.isNaN() && !x.isFinite() && !y.isFinite()      // true\n```\n\n`toFraction` accepts an optional maximum denominator.\n\n```js\nz = new Decimal(355)\npi = z.dividedBy(113)        // '3.1415929204'\npi.toFraction()              // [ '7853982301', '2500000000' ]\npi.toFraction(1000)          // [ '355', '113' ]\n```\n\nAll calculations are rounded according to the `precision` and `rounding` properties of the Decimal constructor.\n\nMultiple Decimal constructors can be created, each with its own independent configuration.\n\n```js\nDecimal.set({ precision: 5, rounding: 4 })\n\nDec = Decimal.clone({ precision: 9, rounding: 1 })\n\nx = new Decimal(5)\ny = new Dec(5)\n\nx.div(3)                           // '1.6667'\ny.div(3)                           // '1.66666666'\n```\n\nThe value of a Decimal is stored as digits, exponent, and sign. Treat these properties as read-only.\n\n```js\nx = new Decimal(-12345.67)\nx.d                            // [ 12345, 6700000 ]    digits (base 10000000)\nx.e                            // 4                     exponent (base 10)\nx.s                            // -1                    sign\n```\n\nSee the [API reference](doc/API.html) for the full method list.\n\n## Extensions\n\nThis fork adds helpers that keep the original Decimal API intact:\n\n```js\nDecimal.version                    // '11.0.0'\n\nx = Decimal.from('1e-7')\nx.toPlainString()                  // '0.0000001'\nx.copy().eq(x)                     // true\nx.shift(3)                         // '0.0001'\n\nnew Decimal(42).isSafeInteger()    // true\nnew Decimal(42).toBigInt()         // 42n\n\nDecimal.tryFrom('oops')            // null\nDecimal.pi().toSD(5)               // '3.1416'\nDecimal.e().toSD(5)                // '2.7183'\n\nDecimal.config({ precision: 8 })\nDecimal.reset()                    // restore defaults\n```\n\nInvalid values throw a `Decimal.Error` (a subclass of `Error`) whose message still starts with `[DecimalError]`.\n\n## Configuration\n\n| Property | Default | Description |\n| --- | --- | --- |\n| `precision` | `20` | Maximum significant digits of a calculation |\n| `rounding` | `4` (`ROUND_HALF_UP`) | Rounding mode |\n| `minE` | `-9e15` | Minimum exponent |\n| `maxE` | `9e15` | Maximum exponent |\n| `toExpNeg` | `-7` | Exponent at and beneath which `toString` uses exponential notation |\n| `toExpPos` | `21` | Exponent at and above which `toString` uses exponential notation |\n| `modulo` | `1` | Remainder mode for `mod` |\n| `crypto` | `false` | Use cryptographically secure random values |\n\nRounding modes:\n\n| Constant | Value | Behaviour |\n| --- | --- | --- |\n| `ROUND_UP` | `0` | Away from zero |\n| `ROUND_DOWN` | `1` | Towards zero |\n| `ROUND_CEIL` | `2` | Towards `+Infinity` |\n| `ROUND_FLOOR` | `3` | Towards `-Infinity` |\n| `ROUND_HALF_UP` | `4` | Nearest neighbour; if equidistant, up |\n| `ROUND_HALF_DOWN` | `5` | Nearest neighbour; if equidistant, down |\n| `ROUND_HALF_EVEN` | `6` | Nearest neighbour; if equidistant, towards even |\n| `ROUND_HALF_CEIL` | `7` | Nearest neighbour; if equidistant, towards `+Infinity` |\n| `ROUND_HALF_FLOOR` | `8` | Nearest neighbour; if equidistant, towards `-Infinity` |\n| `EUCLID` | `9` | Euclidean division (modulo) |\n\n```js\nDecimal.set({\n  precision: 20,\n  rounding: Decimal.ROUND_HALF_UP\n})\n```\n\n## Test\n\nFrom the project root:\n\n```bash\nnpm test\n```\n\nRun a single test module:\n\n```bash\nnode test/modules/toFraction\n```\n\nTo run the tests in a browser, open `test/test.html`.\n\n## Licence\n\n[The MIT Licence](LICENCE.md)\n\nMade by ArtemCheiv.\n","readmeFilename":"README.md","_rev":"1-d5603342419e73f0f9da197cb1250f2c"}