PHP:为什么printf(“%。2f”,0.02)输出0.024?为什么不是0.02?

When the code is :

<?php printf("%.2f", 0.02);?>

output: 0.02

When the code is :

<?php var_dump(printf("%.2f", 0.02));?>

output: 0.02int(4)

When the code is :

<?=printf("%.2f", 0.02)?>

output: 0.024

<?=var_dump(printf("%.2f", 0.02))?>

output: 0.02int(4)

Why <?=printf("%.2f", 0.02)?> isn't outputing 0.02? Does <?=printf("%.2f", 0.02)?> correspond to <?php var_dump(printf("%.2f", 0.02));?>?

I think you've missed something important here. From the manual

Returns the length of the outputted string.

So, while printf outputs to the browser, it returns the length of 0.02, which is 4