防止JavaScript数字函数舍入大数字 [英] Prevent JavaScript Number function from rounding big numbers

查看:110
本文介绍了防止JavaScript数字函数舍入大数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个字符串值'9223372036854775807'。我在JavaScript中使用Number()函数将其转换为数字值使用以下代码

I have a string value ' 9223372036854775807 '. I use Number() function in JavaScript to convert it to a number value using the following Code

var numericVal = Number(' 9223372036854775807 ');

当我检查numericVal中的值时,它是9223372036854776000.如何获得等效值表示数字的字符串?

when i check the value in numericVal, it is 9223372036854776000. How can I get the equivalent value for the string representing the Number?

推荐答案

JavaScript编号 Double Precision Floats ;可以精确存储的最大整数是2 ^ 53(9007199254740992)。
如果你真的需要它,你可以在你面前有一些有趣的数学,或者你可以使用像 big.js

JavaScript numbers are Double Precision Floats; the largest integer that can be precisely stored is 2^53 (9007199254740992). If you actually need it in a number you have some fun math ahead of you, or you can use a library such as big.js

这篇关于防止JavaScript数字函数舍入大数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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