dongpenggan6812 2013-09-25 06:29
浏览 33
已采纳

使用基于MYSQL阵列的查询将浮点值VALUES更改为小数点

I'm having the trouble of assigning decimal points, when i want to display the price of my product in the table in one of my php pages. Using number_format solves the problem when i want to display in the normal version, but when i want to display in a numeric array type, i don't know how to make the queried value into decimal points.

Any ideas? the data is stored as a float value, and the column price from menurecords is displayed as; how to input a decimal value here?

    echo "<td align='center'><font color='#FFFFFF'>".$row[2]."</font></td>";
  • 写回答

1条回答 默认 最新

  • dongyan5239 2013-09-25 06:33
    关注
    select
        format(field, 2) as formatted
    from
        table
    

    Please take note that Format() returns a string, and the result will be with two decimal places (in the above example) - i.e. 10 will be formatted as 10.00.

    OR you can also use

    You want to use the TRUNCATE command.

    http://dev.mysql.com/doc/refman/5.0/en/mathematical-functions.html#function_truncate

    TRUNCATE(0.166, 2) = 0.16
    

    or

    ROUND(0.166, 2) = 0.17
    

    hope this will sure help you.

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

报告相同问题?

悬赏问题

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