-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
  • 5,377
  • 12
  • 50
  • 56

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,062
  • 9
  • 52
  • 87
0

Use round:

$result = $xrpprice*$rate*$fxrates['rates']['MXN'];
echo round($result,2);
aidinMC
  • 1,302
  • 3
  • 16
  • 30