donglinxia1541 2017-11-21 01:58 采纳率: 0%
浏览 13
已采纳

如何防止PHP做自动轮大浮?

I have big float on database : 20202166.16

When I call on PHP:

$num = odbc_result($sqlQuery,0);
$number = number_format($num,2,',','.');

I get 20.202.170,00 but I want 20.202.166,16

Any idea how to prevent auto-rounding?

  • 写回答

1条回答 默认 最新

  • douxing8855 2017-11-21 15:16
    关注

    Sounds like it's not PHP based on the answers in the comments. You don't say what database you're using but taking a guess it might be MySQL?

    Problems with Floating-Point Values

    Floating-point numbers sometimes cause confusion because they are approximate and not stored as exact values. A floating-point value as written in an SQL statement may not be the same as the value represented internally. Attempts to treat floating-point values as exact in comparisons may lead to problems. They are also subject to platform or implementation dependencies. The FLOAT and DOUBLE data types are subject to these issues. For DECIMAL columns, MySQL performs operations with a precision of 65 decimal digits, which should solve most common inaccuracy problems.

    Source: https://dev.mysql.com/doc/refman/5.7/en/problems-with-float.html

    Try changing the column type to DECIMAL and see if that resolves the issue.

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

报告相同问题?

悬赏问题

  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题
  • ¥20 RL+GNN解决人员排班问题时梯度消失
  • ¥60 要数控稳压电源测试数据
  • ¥15 能帮我写下这个编程吗
  • ¥15 ikuai客户端l2tp协议链接报终止15信号和无法将p.p.p6转换为我的l2tp线路