【问题标题】:Limit decimals to three digits laravel将小数限制为三位 laravel
【发布时间】:2021-08-25 09:08:38
【问题描述】:

以前的代码

$product->selling_price

结果 1.1000

我试过了

({{ ceil($product->selling_price) }})

1

我想要 1.100(科威特第纳尔)

【问题讨论】:

    标签: php laravel laravel-blade


    【解决方案1】:

    你可以使用number_format

    number_format((float)$product->selling_price, 3, '.')
    

    PHP官方文档

    number_format ( float $num , int $decimals = 0 , string|null $decimal_separator = "." , string|null $thousands_separator = "," ) : 字符串

    使用分组的千位和可选的十进制格式化数字 数字。

    参考:https://www.php.net/manual/en/function.number-format.php

    【讨论】:

    • 工作感谢亲爱的
    • {{ number_format((float)$product-> sell_price, 3, '.', '') }}
    猜你喜欢
    • 2014-07-07
    • 1970-01-01
    • 2023-01-08
    • 1970-01-01
    • 1970-01-01
    • 2012-12-05
    • 2022-01-11
    • 2014-10-03
    • 1970-01-01
    相关资源
    最近更新 更多