Bird
0
0

Which of the following is the correct syntax to print a floating-point number with 3 decimal places using printf in PHP?

easy📝 Syntax Q3 of 15
PHP - Output and String Handling
Which of the following is the correct syntax to print a floating-point number with 3 decimal places using printf in PHP?
Aprintf("%.3f", 3.14159);
Bprintf("%3f", 3.14159);
Cprintf("%f.3", 3.14159);
Dprintf("%f", 3.14159, 3);
Step-by-Step Solution
Solution:
  1. Step 1: Understand the precision syntax in printf

    %.3f means print a float with 3 digits after the decimal point.
  2. Step 2: Check each option's syntax

    printf("%.3f", 3.14159); uses %.3f correctly; others misuse the format or extra arguments.
  3. Final Answer:

    printf("%.3f", 3.14159); -> Option A
  4. Quick Check:

    %.3f formats float with 3 decimals [OK]
Quick Trick: Use %.nf to print float with n decimal places [OK]
Common Mistakes:
  • Omitting the dot before precision
  • Passing extra arguments incorrectly
  • Misplacing precision after %f

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes