-3

Anyone knows how i can convert How to convert numbers like 902.1 or 902 to 900 in php..i have tried both ceil and floor like below but still same issue

$amount = 902.1
  $amount2 = floor($amount);
  return $amount2;

   returns 902

but i want to return either 900 or 910..something like this

PPK
  • 41
  • 1
  • 9
  • i just want to round it to nearest 10th...becos the api i am using dont allow values like 902, or 903 or this kind of numbers...its only 910, 920 , 110 and this kind format – PPK Jan 28 '20 at 10:22
  • @trey..yes it does – PPK Jan 28 '20 at 10:24
  • _“i have tried both ceil and floor”_ - those round up or down to the next _integer_ value. Since you are starting out with integer values already, _of course_ both do nothing. – 04FS Jan 28 '20 at 10:27

1 Answers1

0

This did it for me

$number = ceil($amount / 10) * 10;
PPK
  • 41
  • 1
  • 9