且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在Javascript中检查值是否为整数(特殊情况1.0应该为float)

更新时间:2023-11-28 20:41:10

如果您键入

var a = 1;
var b = 1.0;

ab的存储方式完全相同.没有没有差异.这是因为JavaScript中只有一种数字存储类型,它是 IEEE754双精度浮点数.

a and b are stored exactly the same way. There's no difference. That's because there's only one storage type for numbers in JavaScript, it's IEEE754 double precision floating point.

如果要使它们保持不同,请不要使用数字格式,例如,可以将它们保留为字符串.

If you want to keep them different, don't use the number format, you may keep them as strings for example.