var number= +1000;
number.toLocaleString(); // output "1,000"
哪里
1000.toLocaleString() // output error Uncaught SyntaxError: Invalid or unexpected` token
最佳答案
当对 1000 这样的数字使用 Number 方法时,您应该通过双点表示法来实现,例如1000..toLocaleString()
这样做的原因是 1000.
解释为带有浮点的数字,这就是 1000.toLocaleString
失败的原因
你也可以去:
数字(1000).toLocaleString()
(1000).toLocaleString()
变量编号 = 1000; number.toLocaleString()
关于javascript - 将 .toLocaleString() 与存储整数的变量一起使用是可行的,而与直接数字一起使用而不存储在变量中则不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38990590/