Click here to Skip to main content
13,901,062 members
Rate this:
 
Please Sign up or sign in to vote.
See more:
How can I add or subtract amount based on decimal points in PHP / CI? I.e. if the amount is 5.11 it should return 5 and if amount is 5.66 it should return 6. Subtract +1 if decimal is greater then 50 and subtract if lesser or equal to 50

What I have tried:

We can use decimal detection and then ceil and floor function accordingly but seeking if there is library or function avaliable
Posted
Updated 16-Oct-18 16:57pm

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

What you've described is just normal rounding (unless I am missing something)

PHP accomplishes this with the round function.

round(5.11);
round(5.6);

Round function documentation

PHP: round - Manual[^]
   
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Cookies | Terms of Service
Web03 | 2.8.190306.1 | Last Updated 16 Oct 2018
Copyright © CodeProject, 1999-2019
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100