2

I have read the documentation and have clear idea of round but i didn't find useful information to solve the problem.

The problem is i have float number which is let say 1.09 and i want to display it 2 instead of 1. if we use round function it display 1. Help me solve this problem.

MORE DETAILS...

$TotalPaidRemaining=1090;
$monthly_installments=1000;
$MakingNumberOfMonths=$TotalPaidRemaining/$monthly_installments;
echo round($MakingNumberOfMonths, 0, PHP_ROUND_HALF_UP);// it display 1. i want it display 2..

What i want is if the value after decimal point is greater than 0. For example 0.01. I want to consider it as 1.

Hope i am clear at my question.

0

3 Answers 3

3

Use the ceil() function instead.

$number = ceil(0.1); // $number will be 1

From the documentation :

Returns the next highest integer value by rounding up value if necessary.

Sign up to request clarification or add additional context in comments.

Comments

2

You can use the ceil() php function instead of round(). It will round up your values. Docs: http://php.net/manual/en/function.ceil.php Example: ceil(1.09); // return 2

Comments

0

You could use ceil($yourNumber), which will round the number to its next higher integer.

Or you could use round($yourNumber + 0.499999999999999).

Or you could use floor($yourNumber + 1), which rounds the number to its previous highest integer.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.