PHP Array Exercises : Floor decimal numbers with precision
18. Floor Decimal with Precision
Write a PHP function to floor decimal numbers with precision.
Note: Accept three parameters number, precision, and $separator
Sample Data :
1.155, 2, "."
100.25781, 4, "."
-2.9636, 3, "."
Sample Solution:
PHP Code:
Output:
1.15 100.2578 -2.964
Flowchart:

For more Practice: Solve these Related Problems:
- Write a PHP function that floors a decimal number to a specified precision and returns the result as a string using a custom separator.
- Write a PHP script to implement a function that rounds down a number to a given number of decimal places without using round().
- Write a PHP program to compare the output of your custom floor function with PHP's floor() and format the output with the specified separator.
- Write a PHP function to handle negative decimal numbers and floor them to the desired precision, ensuring correct formatting.
Go to:
PREV : Lowest Non-zero Integer Function.
NEXT : Print Specific Elements from Multidimensional Array.
PHP Code Editor:
Contribute your code and comments through Disqus.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.