您好我试图找出符号的减号或小数点,但似乎无法弄清楚该怎么做。
这就是我所拥有的:
if (strpos($dec, '.')){
echo "A decimal occured."
}
答案 0 :(得分:1)
PHP的func pickerView(_ pickerView: UIPickerView, viewForRow row: Int, forComponent component: Int, reusing view: UIView?) -> UIView {
let pickerLabel = UILabel()
pickerLabel.textColor = UIColor.black
pickerLabel.text = "10"
pickerLabel.textAlignment = NSTextAlignment.center
pickerLabel.sizeToFit()
return pickerLabel
}
将返回减号或小数点的位置(如果找到),或strpos
(如果找不到)。
false
请注意,我使用$spaces = '2,223.00';
$pos = strpos($spaces, '.');
if (false === $pos) {
echo 'No decimal found';
} else {
echo 'Decimal found at ' . $pos;
}
来检查结果。
答案 1 :(得分:0)
if(preg_match ( ".", $spaces )){
echo "A decimal occured."
}
if(preg_match ( "-", $spaces )){
echo "A minus occured."
}
或者比较买了:
if(preg_match ( "/(\.|-)/" , $spaces )){
echo "Minus or decimal";
}
您需要确保$ spaces是一个字符串
strval($spaces);