Garg Garg - 3 months ago 5x
PHP Question

Simple round function doesn't round

I'm trying to round one value to 8 symbol after decimal but it doesn't round anything. For example:

result: 0.018364348677767

I want to round and output 8 symbols only after

This is the function

public static function getUSDRate()
$urldata = get_curl_content('');
$rates = json_decode($urldata, TRUE);
if (!$rates) {
return '-';
$usdRate = $rates['USD']['sell'];
if (!$usdRate) {
return '-';
return round($usdRate, 8);

Function calling


Then when I call the function it echo whole number...


If you want the result to have only 8 decimals, you should use:

echo round($singles->price/getUSDRate(), 8);

With the information in your question, we can see that you are rounding too early, since you perform more calculations later. You could probably remove the rounding from getUSDRate() function.