convert scientific notation to decimal with php

前端 未结 3 1935
盖世英雄少女心
盖世英雄少女心 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;
    
    0 讨论(0)
  • 2021-01-29 06:16

    Use the exemple below to convert Scientific Notation to float/decimal on PHP:

    echo sprintf('%f', floatval('-1.0E-5'));//default 6 decimal places
    echo sprintf('%.8f', floatval('-1.0E-5'));//force 8 decimal places
    echo rtrim(sprintf('%f',floatval(-1.0E-5)),'0');//remove trailing zeros
    
    0 讨论(0)
  • 2021-01-29 06:23

    I just use number_format()

    Actual situation on your PHP:

    $n=pow(71663616,2);
    echo $n //5.1356738581955E+15
    

    Now calling the decimal notation:

    $n=pow(71663616,2);
    echo number_format($n) //5,135,673,858,195,456
    
    0 讨论(0)
提交回复
热议问题