【问题标题】:How can i return 2 numbers with one decimal?如何返回 2 个带一位小数的数字?
【发布时间】:2016-10-06 09:10:28
【问题描述】:

我从我的查询中返回这个号码:44397.6345

我想以这种格式显示它:44.4

【问题讨论】:

  • 除以一千然后用round()?
  • 要是有某种搜索引擎就好了....

标签: php decimal rounding number-formatting


【解决方案1】:

只需使用number_format:

number_format(44397.6345 / 1000, 1)

(注意:根据您的示例,我假设您还想将其除以 1000)

【讨论】:

  • 我使用了数字格式,但没有除以 1000。
【解决方案2】:

试试这个,

$number = 1000;
echo  number_format((float)$number, 1, '.', '');// 1000.0
$number = 44397.6345;
echo  number_format((float)$number, 1, '.', '');// 44397.6

注意:输出为字符串。

【讨论】:

    猜你喜欢
    • 2022-12-05
    • 1970-01-01
    • 2010-11-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-08-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多