# How to get a number to round to a whole number in php?

I have a part of my code that does calculations but it gives too many numbers behind the decimal sometimes.

How do I tell it to only produce whole numbers?
``````if(\$outcome == "Human wins") {
\$humanWins++;
\$humanPercent = (\$humanWins/\$total) * 100;
}
else if(\$outcome == "Computer wins") {
\$computerWins++;
\$computerPercent = (\$computerWins/\$total) * 100;
}
else if(\$outcome == "Tie") {
\$ties++;
\$tiesPercent = (\$ties/\$total) * 100;
}
``````
###### Who is Participating?

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Commented:
If you want to round to the nearest whole number use round function

\$computerPercent = round((\$computerWins/\$total) * 100);

in this case (2/3) * 100 = 66.6666666667 it will round to 67
in this case (1/3) * 100 = 33.3333333333 it will round to 33

if you always want it to round up use ceil function

\$computerPercent = ceil((\$computerWins/\$total) * 100);
in this case (2/3) * 100 = 66.6666666667 it will round to 67
in this case (1/3) * 100 = 33.3333333333 it will round to 34

if you always want it to round down use floor function
in this case (2/3) * 100 = 66.6666666667 it will round to 66
in this case (1/3) * 100 = 33.3333333333 it will round to 33
0

Experts Exchange Solution brought to you by

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

WebDevCommented:
If you only want whole numbers, then the round() function would do it. It'll round up or down according to the value after the decimals.

If you want it to round up, use ceil()

If you want it to round down, use floor()

``````\$humanPercent = round((\$humanWins/\$total) * 100);
``````
0
Author Commented:
Thanks!
0
###### It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.