Which of the following is the correct way to round a float to 2 decimal places in PHP?
easy📝 Syntax Q12 of 15
PHP - Variables and Data Types
Which of the following is the correct way to round a float to 2 decimal places in PHP?
Around(3.14159)
Bround(3.14159, '1')
Cround(3.14159, 0.02)
Dround(3.14159, 2)
Step-by-Step Solution
Solution:
Step 1: Check round() function usage
The round() function takes a float and an integer number of decimal places as arguments.
Step 2: Validate each option
round(3.14159, 2) uses round(3.14159, 2) which rounds to 2 decimals correctly. round(3.14159, '1') uses a string '1' which is invalid. round(3.14159) rounds to 0 decimals by default. round(3.14159, 0.02) uses 0.02 which is not a valid precision argument.