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,050 points
745 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.

Related Questions In PHP

0 votes
1 answer

What are the vulnerability related to PHP Form?

Hii, The $_SERVER["PHP_SELF"] variable can be used by ...READ MORE

answered Feb 13, 2020 in PHP by Niroj
• 82,880 points
3,052 views
0 votes
1 answer

How to Validate Form Data With PHP?

Hey @kartik, The first thing we will do ...READ MORE

answered Feb 13, 2020 in PHP by Niroj
• 82,880 points
3,212 views
0 votes
1 answer

What is a Cookie? How to create Cookies With PHP?

A cookie is often used to identify ...READ MORE

answered Feb 13, 2020 in PHP by Niroj
• 82,880 points
3,705 views
0 votes
1 answer

How to validate E-mail and URL of Php form?

hey, The code below shows a simple way ...READ MORE

answered Feb 13, 2020 in PHP by manish
2,304 views
0 votes
1 answer

What is Php Mysql Database? How php connect to database?

Hello kartik, MySQL is the most popular database ...READ MORE

answered Feb 25, 2020 in PHP by Dey
1,065 views
0 votes
1 answer

How to retrieve or obtain data from the MySQL database using PHP?

Hello kartik,  Actually there are many functions that  ...READ MORE

answered Mar 27, 2020 in PHP by Niroj
• 82,880 points
3,291 views
0 votes
0 answers

Automatic conversion from int to string in PHP

In PHP the variable of type integer ...READ MORE

Jun 12, 2022 in PHP by narikkadan
• 63,720 points
939 views
0 votes
0 answers

Show a number to two decimal places

What's the correct way to round a ...READ MORE

Jun 24, 2022 in PHP by narikkadan
• 63,720 points
535 views
0 votes
0 answers

What's the maximum value for an int in PHP?

Ignoring the special libraries that allow you ...READ MORE

Jul 25, 2022 in PHP by Kithuzzz
• 38,020 points
515 views
0 votes
0 answers

Converting an integer to a string in PHP

Is it possible to change an integer ...READ MORE

Aug 1, 2022 in PHP by Kithuzzz
• 38,020 points
872 views
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