What is the difference between %0.2lf and %.2lf as printf placeholders?

前端 未结 4 1302
耶瑟儿~
耶瑟儿~ 2021-02-08 07:15

I am aware that putting any number of 0\'s before the width of the placeholder implements zero-padding. For example, printf(\"%02d\", 6); prints

4条回答
  •  旧巷少年郎
    2021-02-08 08:08

    They are "equivalent". If you were to use "%07.2", then it would make a difference, by adding extra zeros on the front.

    Edit: Originally had "%04.2", which of course doesn't make any difference, because a float with two decimals is always 4 wide anyway.

提交回复
热议问题