0

I am using the easybitcoin.php library and in my application. I use the getreceivedbyaddress method in php. It returns 0, but in my shell when I use bitcoin-cli it returns 0.000000000.

My question is, how can I return in php the same as the shell?

Tried this, $ data2 = shell_exec ('bitcoin-cli getreceivedbyaddress address'); and it returns 0.00000000, but is there another way?

Murch
  • 75,206
  • 34
  • 186
  • 622
Aisakk
  • 17
  • 6

1 Answers1

1

I think this is more of a PHP question versus bitcoin, but that's how PHP handles a zero float. https://www.php.net/manual/en/language.types.type-juggling.php

$var = 0.00000000;
echo $var;

Returns:

0

If you want to force a zero value to eight decimals you can use number_format() https://www.php.net/manual/en/function.number-format

$var = 0.00000000;
$formatted = number_format($var, 8);
echo $formatted;

Returns:

0.00000000
m1xolyd1an
  • 5,636
  • 2
  • 14
  • 30