0

how can i shorten a long number with php ? So a number like 0.3483748937847832 would become 0.34

456543646346
  • 973
  • 4
  • 15
  • 22

2 Answers2

1

Please search stackoverflow first - from PHP: show a number to 2 decimal places

number_format()

return number_format((float)$number, 2, '.', '');

https://stackoverflow.com/a/4483561/689579

or

$padded = sprintf('%0.2f', $unpadded); // 520 -> 520.00

https://stackoverflow.com/a/4483715/689579

Community
  • 1
  • 1
Sean
  • 12,443
  • 3
  • 29
  • 47
0

Use round

echo round($number,2);

Orangepill
  • 24,500
  • 3
  • 42
  • 63