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

前端 未结 4 1289
耶瑟儿~
耶瑟儿~ 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:03

    Blockquote

    Basically when we % w.p f for output w refers to the minimum number of position to be use for displaying the value and p refers to the number of digit after decimal point. %3.2f floating point having 3 wide and 2 number after decimal

    %0.2ffloating point at least 0 wide and 2 number after decimal

    %.2f floating point at least 0(default) wide and a precision of 2)

    But don't misunderstand about the 0 width if you use %0.2f it can auto adjust its minimum width.

提交回复
热议问题