Moving decimal from the right in PHP

后端 未结 2 799
情书的邮戳
情书的邮戳 2021-01-29 00:50

I have large numbers and their decimals points. Here are some examples and what should return:

Number: 300000
Decimals: 8
Should return: 0.00300000

Number: 7000         


        
相关标签:
2条回答
  • 2021-01-29 01:12

    Divide by 10 to the power of the number of decimals:

    $result = $number / (10 ** $decimals);
    
    0 讨论(0)
  • 2021-01-29 01:16

    Divide by ten to the power of decimals?

    $n = 700000000;
    $d = 8;
    
    Echo $n/pow(10,$d);
    

    https://3v4l.org/MdoW1

    0 讨论(0)
提交回复
热议问题