Moving decimal from the right in PHP

后端 未结 2 810
情书的邮戳
情书的邮戳 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);
    

提交回复
热议问题