what will be the alternative to var to store/calculate a large value.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-03-2024 10:33 PM
there is a requirement to do large value calculation, but the var datatype is not supporting it. for example we need to calculate the probability using permutation or combination, for which we need to calculate the factorial for large value say in million. now when i trying to do it var is not able to handle the value & returning NAN. is there any alternative way to var (datatype) or is there any way to use the js math library.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-03-2024 10:52 PM
In JavaScript, the var datatype is not the issue when dealing with large numbers; rather, it's the limitations of the number representation in JavaScript. JavaScript uses a 64-bit floating-point representation for numbers, which has limited precision and cannot accurately represent very large numbers or numbers with many decimal places.
For calculations involving very large numbers, such as factorials in the millions or beyond, you'll need to use a library that supports arbitrary-precision arithmetic. One popular library for this purpose is the BigInt type, which is available in modern JavaScript environments. However, it's worth noting that BigInt is not supported in all browsers, so its usage might be restricted depending on your target environment.
Please Mark ✅Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-03-2024 11:18 PM
as per my knowledge we can't use bigInt either in service now.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-03-2024 11:54 PM
Yeah. Almost similar issue, pls check the below link
Please Mark ✅Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.
Thanks