数字角度的错误计算 [英] Wrong calculations on number angular

查看:99
本文介绍了数字角度的错误计算的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

In angular 6 i am getting the invalid values when adding the large value numbers.

Is there any solution around this to handle large numbers for addition, comparison, etc?





我尝试过:





What I have tried:

9007199254740992==9007199254740993 
o/p = true

9007199254740992+0.98 
o/p = 9007199254740992

推荐答案

JavaScript中的数字不能任意大或精确 - 数字是64位值(基于IEEE 754标准),您已达到数字限制。您将不得不使用外部库,例如 bignumber.js [ ^ ]。
Numbers in JavaScript cannot be arbitrarily large or precise - numbers are 64-bit values (based on the IEEE 754 standard) and you've hit the limit with your number. You'll have to use an external library such as bignumber.js[^] for arbitrary precision.


这些是 JavaScript '功能'。您可能会在网上找到许多变通方法。例如,请参阅使用JavaScript中的大整数 [ ^ ]。
Those are JavaScript 'features'. You may find many workarounds on the web. See, for instance Working with large integers in JavaScript[^].


这篇关于数字角度的错误计算的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆