
The following code can come in handy when dealing with numbers using php.
Float value
1 2 |
echo floatval(4.0); //4 echo floatval(4.2168); //4.2168 |
Round to nearest integer
1 2 |
echo round(3.4); // 3 echo round(3.6); // 4 |
Round up to nearest integer
1 |
echo ceil(4.4); //5 |
Money format
1 |
echo money_format('$%i', 3.4); // echos '$3.40' |