PHP round to integer

0 votes

I want to round the number and get a proper integer to make it an array key. This is the answer that I know:

$key = (int)round($number)

As far as I know (int) just truncates any decimals and since round($number) returns a float with theoretically limited precision, is it possible that round($number) returns something like 7.999999... and then $key is 7 instead of 8?

Is there any better solution to do this?

May 30, 2022 in PHP by Kichu
• 19,040 points

edited 4 days ago 83 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP