Pages

Wednesday, March 6, 2013

Print the next highest integer value by rounding up value with php

To make a round value from an decimal value like:

3.4 to 4
5.6 to 6

you can use the php ceil function, ceil - Round fractions down

its syntax is float ceil ( float $value )

example 

echo ceil(3.4);    // 4
echo ceil(9.999);  // 10


for a value Round fraction down you can use the floor()

example

echo floor(4.3);   // 4
echo floor(9.999); // 9
echo floor(-3.14); // -4


and one is the round() function which returns the nearest round value to the decimal

echo round(3.4);         // 3
echo round(3.5);         // 4
echo round(3.6);         // 4
echo round(3.60);      // 4
echo round(1.955832);  // 1.96
echo round(1241757, -3); // 1242000
echo round(5.0452);    // 5.05
echo round(5.0552);    // 5.06


for more detail or reference you can see the detail documentation on http://www.php.net/manual/en/function.round.php


posted by honeyonsys

No comments:

About Me

Hi,My name is Harish Kumar.I am a web developer by profession.I am working in the same field since 2008. About my skills i am proficient in HTML,CSS,JAVASCRIPT/JQUERY/ ANGULAR,PHP,MYSQL,APACHE,LINUXAJAX, REST,etc...