duanli9569 2016-01-16 10:21 采纳率: 100%
浏览 40
已采纳

php乘以逗号和点分隔的int值

In my current application a user can have a "prepaid" amount of money on his account. The value is stored in cents. Now in case of a user tries to transfer money from one account to another he should be able to use values like: "1,53", "1.53" and "1". Now I need to check if the entered amount is below the amount he's able to transfer.

 if (($request->amount * 100) <= $user->calculateAmount())

The function $user->calculateAmount() returns values like for example "351" which stands for 3,51€ (saved in cents). I know the problem is the ",", using a "." works fine, but user should be able to use both. Is there a better way or did I need to use str_replace()?

  • 写回答

1条回答 默认 最新

  • duanbeng6709 2016-01-16 10:29
    关注

    You can use this: http://codepad.org/NW4e9hQH

    Currently there are no other method to parse this to float.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度