How to specify setprecision rounding

前端 未结 4 2142
不思量自难忘°
不思量自难忘° 2020-12-02 00:34

Can I specify setprecision to round double values when stream to std output?

ofile << std::setprecision(12) << total_run_time/TIME << \"\\n         


        
4条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-02 01:19

    Another approach is to defeat the rounding by subtracting, in your second case, 0.000005 from the double before outputting it:

    total_run_time / TIME - 0.000005
    

    In many ways I prefer this as it avoids the potential for integer overflow.

提交回复
热议问题