【问题标题】:How to round decimals like this?这样的小数怎么舍入?
【发布时间】:2019-11-11 01:37:03
【问题描述】:

我想对小数进行四舍五入,我的代码正在运行,但我想得到这样的输出。

样本

49.155
49.555
49.955

尝试使用 {$var|round:0}

输出给予

49
50
50

查看输出

49
49
49

【问题讨论】:

    标签: php math rounding smarty3


    【解决方案1】:

    使用数学底函数。它会给你最小的十进制数(对于正数)。

    import math
    math.floor(x)
    

    【讨论】:

    • 这是什么语言?
    【解决方案2】:

    在 Smarty 中的语法是

    {$var|floor}
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-09-05
      • 1970-01-01
      • 1970-01-01
      • 2011-12-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多