what will be the alternative to var to store/calculate a large value.

Pun
Tera Contributor

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.

3 REPLIES 3

Maddysunil
Kilo Sage

@Pun 

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

Pun
Tera Contributor

as per my knowledge we can't use bigInt either in service now.

 

@Pun 

Yeah. Almost similar issue, pls check the below link

https://www.servicenow.com/community/developer-forum/javascript-not-parsing-large-number-in-json-cor... 

 

Please Mark Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.

 

Thanks