Multiple choice php

Which of the following snippets prints a representation of 42 with two decimal places?

  1. printf("%.2d\n", 42);

  2. printf("%1.2f\n", 42);

  3. printf("%1.2u\n", 42);

  4. none of the above

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

The '%f' specifier is used for floating-point numbers. In printf, '%1.2f' tells PHP to treat the input as a float and display it with at least one digit before the decimal and exactly two digits after. Even though 42 is an integer, it is cast to 42.00.