dongtiao5094 2017-06-08 12:50
浏览 200
已采纳

当0.00是可接受的值时,检查执行字符串到浮点转换的错误

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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器