MySQL数据imoprt mongo数据库。
price float(15,2) in mysql, mongo is not float(15,2).
我想确定一个 var $price
有两位小数。
例如。 100.00 是正确的,100 或 100.0 是错误的。
例1
$price = 100.00;
$price
有两位小数,没错。
例2
$price = 100.0;
$price
没有两位小数,这是错误的。
最佳答案
我喜欢用正则表达式来做这些事情
function validateTwoDecimals($number)
{
if(preg_match('/^[0-9]+\.[0-9]{2}$/', $number))
return true;
else
return false;
}
(感谢 Fred-ii- 的更正)
关于php判断一个float变量有两位小数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26792784/