Javascript负数(Javascript negative number)
我想检查一个数字是否为负数。 我正在寻找最简单的方法 ,所以预定义的JavaScript功能将是最好的,但我还没有找到任何东西,这里是我迄今为止,但我不认为这是一个好办法:
function negative(number) { if (number.match(/^-\d+$/)) { return true; } else { return false; } }
I want to check if a number is negative. I'm searching for the easiest way, so a predefined javascript function would be the best but I didn't found yet anything, here is what I have so far but I don't think that this is a good way:
function negative(number) { if (number.match(/^-\d+$/)) { return true; } else { return false; } }
原文:https://stackoverflow.com/questions/3571717
更新时间:2022-07-06 11:07