【问题标题】:Calculation of integer and a floating number整数和浮点数的计算
【发布时间】:2018-03-22 20:49:43
【问题描述】:

我试图计算一个整数和一个浮点数。听起来很简单吧?

但是当我执行以下代码时:

<?php
$decimals = 2;
$dec_point = ',';
$thousands_sep = '.';

$net_no = 851.12;
$net_no = number_format($net_no,$decimals,$dec_point,$thousands_sep);

$months = 13;

$tot_amount = $months * $net_no;
$tot_amount = 
number_format($tot_amount,$decimals,$dec_point,$thousands_sep);

print $tot_amount;

结果我得到 11.063,00,但我希望得到 11.064,56 (13*851.12)。

这里出了什么问题?

【问题讨论】:

    标签: floating-point integer calculator


    【解决方案1】:

    总金额尝试添加 number_format((float) $tot_amount....) 或 $precision

    【讨论】:

    • 我确实添加了 number_format,正如您在 '$tot_amount =' 下方的行中看到的,我将 $decimals 定义为 2,但这只会在数字后面添加一个逗号和两个零
    • 在 number_format($net_no...) 之后移动 net_no = 851.12 怎么样
    猜你喜欢
    • 1970-01-01
    • 2015-09-09
    • 1970-01-01
    • 2013-06-12
    • 2013-04-01
    • 1970-01-01
    • 1970-01-01
    • 2011-01-04
    • 2011-02-02
    相关资源
    最近更新 更多