问题描述
我有一个问题,我建立了一个非常简单的javascript搜索邮政编码。
我正在使用JS Numbers,因为我想检查传递的数字(搜索项)是否更少||等于或更多||等于最大值和最小值。
I have a problem, I build a very simple javascript search for postal codes.I am using JS Numbers because I want to check if the passed number (search term) is less||equal or more||equal to the max and min.
value >= splitZips[0] && value <= splitZips[1]
但Javascript Number var类型删除前导0,这是一个问题,因为我有邮政编码,如01075和邮政编码,如8430.所以它找不到小的4位数代码。
But the Javascript Number var type deletes leading 0, which is a problem because I have postal codes like 01075 and also postal codes like 8430. So it can not find the small 4 digit codes.
任何想法如何解决这个问题?
Any idea how to fix this?
推荐答案
将它们表示为字符串
。在严格模式之外,前导零表示八进制数。否则。
Represent them as a String
. Outside of strict mode, a leading zero denotes an octal number otherwise.
此外,为什么在计算数字时前导零有任何意义?如果需要,只需使用 parseInt(num,10)
。
Also, why would a leading zero have any significance when calculating numbers? Just use parseInt(num, 10)
if you need to.
这篇关于JavaScript编号保留前导0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!