I am currently looking for the most elegant way, to do error-checking on a string to float conversion, when 0.00 shall be an accepted value, but non-numeric characters shall lead to a bailout. Currently I am thinking of testing the string for any other chars than ","/"." or "[0-9]". I`d just like to know, if there is a more elegant/shorter way. Thanks in advance, Oliver !
2条回答 默认 最新
- dongyuedaochen8415 2017-06-08 12:54关注
PHP has a built in function for this.
is_float()
Examples:
is_float(27.25); // This would be true
is_float('abc'); // This would be false
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报
悬赏问题
- ¥15 交替优化波束形成和ris反射角使保密速率最大化
- ¥15 树莓派与pix飞控通信
- ¥15 自动转发微信群信息到另外一个微信群
- ¥15 outlook无法配置成功
- ¥30 这是哪个作者做的宝宝起名网站
- ¥60 版本过低apk如何修改可以兼容新的安卓系统
- ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
- ¥50 有数据,怎么建立模型求影响全要素生产率的因素
- ¥50 有数据,怎么用matlab求全要素生产率
- ¥15 TI的insta-spin例程