setting precision for stringstream
Hi,
How can I set the number of digits after the decimal point in the following example?
std::string str;
std::stringstream stream;
float floatVal=12.012345675f
stream << floatal;
Thanks
streamsize ios_base:: precision() const;
- Returns the precision.
streamsize ios_base:: precision(streamsize prec);
- Sets the precision, returns the previously used precision.
or use the std::setprecision(int n) manipulator.
Or just use boost::format - it's much easier
[ Start Here ! | How To Ask Smart Questions | Recommended C++ Books | C++ FAQ Lite | Function Ptrs | CppTips Archive ]
[ Header Files | File Format Docs | LNK2001 | C++ STL Doc | STLPort | Free C++ IDE | Boost C++ Lib | MSVC6 Lib Fixes ]
[edited by - Fruny on October 10, 2003 4:19:08 AM]
- Returns the precision.
streamsize ios_base:: precision(streamsize prec);
- Sets the precision, returns the previously used precision.
stream.precision(5);stream << floatVal;
or use the std::setprecision(int n) manipulator.
stream << std::setprecision(5) << floatVal;
Or just use boost::format - it's much easier
boost::format fmt( "%.5f" );stream << fmt % floatVal;
[ Start Here ! | How To Ask Smart Questions | Recommended C++ Books | C++ FAQ Lite | Function Ptrs | CppTips Archive ]
[ Header Files | File Format Docs | LNK2001 | C++ STL Doc | STLPort | Free C++ IDE | Boost C++ Lib | MSVC6 Lib Fixes ]
[edited by - Fruny on October 10, 2003 4:19:08 AM]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement