-2

I'm currently working on retrieving data from coinmarketcap API and I would like to limit the strings to 5. I retrieve the data and then multiply the value *1.07 and the result to MXN, but the string is long, like 25.65675734343, I want to limit that string, this is my echo:

echo $xrpprice*$rate*$fxrates['rates']['MXN'];
Ivar
  • 6,138
  • 12
  • 49
  • 61

2 Answers2

0

In PHP you can use number_format to control how many decimal places. Assuming you don't want to limit the whole number to just five characters.

echo number_format($numberToFormat, $numberOfDecimalPlaces);

Please better explain your question. Also, what have you tried?

Michael
  • 4,282
  • 9
  • 55
  • 89
0

Use round:

$result = $xrpprice*$rate*$fxrates['rates']['MXN'];
echo round($result,2);
aidinMC
  • 1,415
  • 3
  • 18
  • 35