Reputation: 535
Say I have a huge number: 999999999.9999999999;
When I try to store this number into a variable, in javascript, It stores the value 1000000000
into that variable.
How do I prevent this from rounding off and store the number as it is?
Upvotes: 1
Views: 592
Reputation: 10569
You could use third party lib to handle this, like bignumber.js
, you can read more about bignumber
here
Please note that this is not possible with the javascript primitive types.
let x = new BigNumber("999999999.9999999999");
console.log(x.toString());
//Add example
console.log(x.plus(23).toString());
<script src="https://cdnjs.cloudflare.com/ajax/libs/bignumber.js/9.0.0/bignumber.min.js"></script>
Upvotes: 1