An arbitrary-precision Decimal type for JavaScript.
Questions tagged [decimal.js]
18 questions
5
votes
1 answer
What does instanceof behave differently inside JSON.stringify()?
I'm using decimal.js for some financial calculations in Node. I'm writing a custom JSON.stringify replacer function, but when I test the property types using instanceof, I get a different result than when I do the same test outside of the replacer…

Nathan Friend
- 12,155
- 10
- 75
- 125
4
votes
0 answers
Big.js Typescript Error: Cannot access ambient const enums when the '--isolatedModules' flag is provided.ts(2748)
I am using big.js in a Typescript react app and the following code
const toFixedRounding = {
[Rounding.ROUND_DOWN]: RoundingMode.RoundDown,
[Rounding.ROUND_HALF_UP]: RoundingMode.RoundHalfUp,
[Rounding.ROUND_UP]:…

Nyxynyx
- 61,411
- 155
- 482
- 830
1
vote
1 answer
Using decimal.js with Typescript
I am trying to use decimal.js with Typescript on the client side of a simple app that was booted with create-react-app - Typescript 2.8.1.
But even for a simple declaration of a = new Decimal(1) I'm just getting an error:
TypeError:…

Neo
- 11
- 5
1
vote
1 answer
TypeScript cannot find module decimal.js - but absolute path works
I am using typescript with node. I can write this without any problems:
import * as $ from "jquery";
The definition file for jquery is in node_modules/@types/jquery. However, neither of the following works with the definition file for decimal.js…

msrd0
- 7,816
- 9
- 47
- 82
1
vote
1 answer
In NodeJS, 'Decimal' works also as 'decimal'
I am installing and using package decimal.js in NodeJS.
This package is described here.
All the examples state that I should be using Decimal. For some reason, it also works when using decimal.
What is the rationale behind this?
I've found a similar…

goodvibration
- 5,980
- 4
- 28
- 61
1
vote
1 answer
Precision issue with Decimal.js tan
I have been using Decimal.js to increase the precision of my function that calculates the mth positive root of a = tan(a) through trial and error. It works, however it returns a "Precision limit exceeded" error for nTan(504) (would return 4.4934...…

met4000
- 83
- 1
- 8
1
vote
1 answer
What is the correct way to calculate percentage increase/decrease between two numbers using Decimal.js?
Desired Behaviour
Show percentage increase/decrease of new_value in comparison to old_value, showing negative indicator when there has been a decrease, and 4 decimal places (with trailing zeros if necessary).
Actual Behaviour
Good
If old_value…

user1063287
- 10,265
- 25
- 122
- 218
1
vote
1 answer
decimal js rounding 3digit numbers [probably a bug?]
I'm using the decimal.js to calculate with numbers and using the advantages by handling big numbers..
Now i came to the point where i want to round numbers to a specific multiplicator.
everything worked fine, until i found this issue;
new…

Synoon
- 2,297
- 4
- 22
- 37
0
votes
1 answer
Error when trying to use decimal.js with typescript
I am trying to use decimal.js in my typescript project. But when I try to execute the below example I get the following error: Cannot assign to read only property 'constructor' of object '[object Object]
import { Decimal } from…

route2
- 1
- 1
0
votes
2 answers
Node.js - Floating point calculation - Intl.NumberFormat vs decimal.js library
I would like to understand the difference between Intl.NumberFormat and decimal.js library.
if Intl.NumberFormat is capable of handling the currency calculations then where does decimal.js library stand and what benefit it does provider over…

Sudhir Dhumal
- 902
- 11
- 22
0
votes
1 answer
What decimal.js rounding mode matches lodash rounding?
I need to refactor lodash _.round() to use decimal.js toDecimalPlaces()
Which of the decimal.js rounding methods matches the way lodash rounds?

steampowered
- 11,809
- 12
- 78
- 98
0
votes
1 answer
How do I stop my Discord bot from calling the wrong command?
I've been coding a sort of calculator Discord bot using JavaScript, but I've encountered a very annoying problem. I made a simple ping command that the bot responded with "pong!" from a tutorial, as this is my first Discord bot. I then created an…
0
votes
0 answers
BigNumber.js simple subtraction giving wrong output
I have used Bignumber.js API for performing some JS calculations involving large numbers. I am performing a subtraction where the result should be 0 but the output is like -0.00000000000000000099. How do I counter such issues with Bignumber…

nraina
- 324
- 2
- 20
0
votes
1 answer
Newb question: I'm just having trouble using decimal.js in my script
I'm very new to JavaScript, and am trying to use decimal.js, for a project that requires its fractional exponents.
I've been trying every variation that I see in examples, but my variable declarations are failing, causing the script to abort. The…

Paul Adamson
- 9
- 3
-1
votes
1 answer
Decimal.js multiplication method does not work propely
I faced the Floating-Point-Precision problem in JavaScript and to solve it i found libraries like Decimal.js or BigNumber.js. It was working fine for me until i tried the following.
I have a total of 60 and a share of 10. So the percentage of the…

Djinii
- 31
- 1
- 8