Convert a double to fixed decimal point in C++

前端 未结 4 1348
忘了有多久
忘了有多久 2021-01-18 12:03

I have a double variable in C++ and want to print it out to the screen as a fixed decimal point number.

Basically I want to know how to write a function that takes a

4条回答
  •  悲&欢浪女
    2021-01-18 12:21

    Assuming I'm remembering my format strings correctly,

    printf("%.*f", (int)precision, (double)number);
    

提交回复
热议问题