Set back default floating point print precision in C++

后端 未结 5 654
夕颜
夕颜 2020-11-30 07:45

I want to control the precision for a double during a comparison, and then come back to default precision, with C++.

I intend to use setPrecision() to s

5条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-11-30 08:00

    You need to keep track of your current precison and then reset back to the same once done with your operations with required modified precison. For this you can use std::ios_base::precision:

    streamsize precision ( ) const;
    streamsize precision ( streamsize prec );
    

    The first syntax returns the value of the current floating-point precision field for the stream.
    The second syntax also sets it to a new value.

提交回复
热议问题