【问题标题】:How can I do in PHP to be similar to Excel Rounddown Formula我怎样才能在 PHP 中做类似于 Excel 舍入公式
【发布时间】:2023-01-03 00:44:36
【问题描述】:

在 excel 舍入中, 舍入(6432737,-7)= 6430000 舍入(3456484,-7)= 3450000

我怎样才能在 PHP 中做到这一点?

拜托,我很欣赏你的想法和答案。

我尝试在 PHP 中使用 floor,但它不起作用。

【问题讨论】:

    标签: php excel-formula


    【解决方案1】:

    您可以使用 PHP 中的 floor 函数将数字向下舍入到最接近的 10 的幂的倍数。例如:

    $rounded = floor(6432737 / 10000000) * 10000000; // $rounded 将是 6430000

    $rounded = floor(3456484 / 10000000) * 10000000; // $rounded 将是 3450000

    floor 函数将数字向下舍入到最接近的整数,因此您可以使用它将数字向下舍入到任何数字的最接近倍数。在上面的示例中,我们将数字除以 10,000,000,然后将其乘以 10,000,000,以将原始数字向下舍入到最接近的 10,000,000 的倍数。

    您还可以使用第二个参数为负值的 round 函数来获得相同的结果:

    $rounded = round(6432737, -7);
    // $rounded will be 6430000
    
    $rounded = round(3456484, -7);
    // $rounded will be 3450000
    

    【讨论】:

    • 你确定这个有效吗?
    猜你喜欢
    • 1970-01-01
    • 2020-10-08
    • 2014-03-05
    • 2011-12-04
    • 2022-08-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-09-01
    相关资源
    最近更新 更多