Bird
0
0

What will be the output of this PHP code?

medium📝 Predict Output Q5 of 15
PHP - Variables and Data Types
What will be the output of this PHP code?
$value = 1.23456789;
echo round($value, 4);
A1.2346
B1.2345
C1.234
D1.235
Step-by-Step Solution
Solution:
  1. Step 1: Understand the round function with 4 decimals

    round() rounds the number to the nearest value at 4 decimal places.
  2. Step 2: Round 1.23456789 to 4 decimals

    1.23456789 rounds up to 1.2346 because the 5th decimal is 6 (>=5).
  3. Final Answer:

    1.2346 -> Option A
  4. Quick Check:

    round to 4 decimals = B [OK]
Quick Trick: round() rounds up if next digit >=5 [OK]
Common Mistakes:
  • Truncating instead of rounding
  • Rounding down incorrectly
  • Confusing decimal places

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes