convert scientific notation to decimal with php

前端 未结 3 1938
盖世英雄少女心
盖世英雄少女心 2021-01-29 05:56

math with bitcoin is giving me problems

        $value = bcmul((float)$TotalMoney, $p,8);
        $value = bcdiv((float)$Value, 100,8);

returns

3条回答
  •  不思量自难忘°
    2021-01-29 06:13

    When working with Bitcoin balances it is recommended to store amounts in a database in satoshis as an integer and then you can convert it back to 8 decimals when displaying it on the screen to users.

    $amount = 0.0132;
    $convert = $amount * 100000000;
    // store in DB as the converted amount 1320000 as an integer
    // when grabbing from DB convert it back
    $databaseValue = 1320000;
    $convertBack = $databaseValue / 100000000;
    $display = number_format($convertBack, 8); 
    echo $display;
    

提交回复
热议问题