Printf width specifier to maintain precision of floating-point value

后端 未结 8 1639
萌比男神i
萌比男神i 2020-11-21 13:39

Is there a printf width specifier which can be applied to a floating point specifier that would automatically format the output to the necessary number of s

8条回答
  •  天命终不由人
    2020-11-21 13:50

    If you are only interested in the bit (resp hex pattern) you could use the %a format. This guarantees you:

    The default precision suffices for an exact representation of the value if an exact representation in base 2 exists and otherwise is sufficiently large to distinguish values of type double.

    I'd have to add that this is only available since C99.

提交回复
热议问题