Security News
Input Validation Vulnerabilities Dominate MITRE's 2024 CWE Top 25 List
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
js-big-decimal
Advanced tools
Work with large numbers on the client side. Round them off to any required precission.
Work with large numbers on the client side with high precision.
Create a new objet of type BigDecimal. Supports parameters of type number
and string
. If string passed cannot be parsed as a number error is thrown. It is recommended to use string as it circumvents the issue of precision with JS native float
implementation and max limit for integer
.
This does not support exponentiation as of yet. 12.456e3
will throw an error.
var n1 = new bigDecimal(12.6789);
var n2 = new bigDecimal("12345.6789");
Returns the string value of the decimal.
console.log(n2.getValue()); // "12345.6789"
By default this returns the number in standard number format, comma after every three digts. Both arguments, digits
- the number of digits (of the integral part) to group by, and separator
- the character to mark the separation. Example of this can be to format a 16 digit number as credit card.
var n3 = n2.getPrettyValue(); // n4 = "12,345.6789"
var num = new bigDecimal(1234567890123456)
var card = num.getPrettyValue(4, '-'); // cardNumber = "1234-5678-9012-3456"
Returns the rounded value to the specified precission (number of digits after decimal). The default is set to 0 if no argument is passed.
var n3 = n1.round(2); // n3 = "12.68"
var n4 = n2.round(); // n4 = "12346"
Add two numbers. Pass in negative for substraction. ensure parameters are strings
.
var sum = bigDecimal.add("23.678", "67.34"); // sum = "91.018"
var diff = bigDecimal.add("67.34", "-23.678"); // diff = "43.662"
FAQs
Work with large numbers on the client side. Round them off to any required precision.
The npm package js-big-decimal receives a total of 39,886 weekly downloads. As such, js-big-decimal popularity was classified as popular.
We found that js-big-decimal demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.
Research
Security News
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.