douqi3064 2018-10-09 03:17
浏览 100

有人可以更简洁地演示变量近似以回显最终变量结果

Can anyone provide an alternative answer to my variable summations without it being a floating point decimal result with the possibility of displaying the final result as in an interger value. Whole numbers to be exact.

With every variable passing results in decimal notation, the final value is larger than the actual pen to paper I get using calculator.

This yeld s echo $terresulting in float value 43402777.777778. It should be more in the lines of 42,849,000 instead of the former, the latter value is my pen and paper. The problem is outputting final value to be non scientific notation. I need in straight interger value.

$tan = 100000;
$g = 30;
$epp = 12;
$days = 365;
$bpe = 4;
$pp = 300;

$apg = $tan / $g; 
$epg = $apg / $bpe;
$ppg = $epg / $epp;
$ypr = $ppg * $pp;
$tep = $ppg * $g;
$ter = $ypr * $tep;

echo $ter;
  • 写回答

1条回答 默认 最新

  • dongqishun6409 2018-10-09 04:09
    关注

    As is typical in computer science, floating-point arithmetic comes with its own set of problems.

    Libraries are generally available for more precision. PHP offers the BC Math functions.

    Your example can be altered to use this...

    $tan = 100000;
    $g = 30;
    $epp = 12;
    $days = 365;
    $bpe = 4;
    $pp = 300;
    
    $apg = bcdiv($tan, $g); 
    $epg = bcdiv($apg, $bpe);
    $ppg = bcdiv($epg, $epp);
    $ypr = bcmul($ppg, $pp);
    $tep = bcmul($ppg, $g);
    $ter = bcmul($ypr, $tep);
    echo '$ter: ', $ter, PHP_EOL; // 42849000
    echo 'Formatted: ', number_format($ter), PHP_EOL; // 42,849,000
    

    Demo ~ https://3v4l.org/vlRaS

    评论

报告相同问题?

悬赏问题

  • ¥15 飞机曲面部件如机翼,壁板等具体的孔位模型
  • ¥15 vs2019中数据导出问题
  • ¥20 云服务Linux系统TCP-MSS值修改?
  • ¥20 关于#单片机#的问题:项目:使用模拟iic与ov2640通讯环境:F407问题:读取的ID号总是0xff,自己调了调发现在读从机数据时,SDA线上并未有信号变化(语言-c语言)
  • ¥20 怎么在stm32门禁成品上增加查询记录功能
  • ¥15 Source insight编写代码后使用CCS5.2版本import之后,代码跳到注释行里面
  • ¥50 NT4.0系统 STOP:0X0000007B
  • ¥15 想问一下stata17中这段代码哪里有问题呀
  • ¥15 flink cdc无法实时同步mysql数据
  • ¥100 有人会搭建GPT-J-6B框架吗?有偿