Avoid trailing zeroes in printf()

前端 未结 14 2177
猫巷女王i
猫巷女王i 2020-11-22 07:18

I keep stumbling on the format specifiers for the printf() family of functions. What I want is to be able to print a double (or float) with a maximum given number of digits

14条回答
  •  一向
    一向 (楼主)
    2020-11-22 07:57

    I would say you should use printf("%.8g",value);

    If you use "%.6g" you will not get desired output for some numbers like.32.230210 it should print 32.23021 but it prints 32.2302

提交回复
热议问题