Format floats like doubles when printing - but add ‘f’ suffix (a lá #291)

This commit is contained in:
Phil Nash 2014-07-09 18:16:40 +01:00
parent ce56209250
commit d89e74faff
7 changed files with 77 additions and 68 deletions

View file

@ -103,9 +103,10 @@ std::string toString( unsigned int value ) {
return toString( static_cast<unsigned long>( value ) );
}
std::string toString( const double value ) {
template<typename T>
std::string fpToString( T value, int precision ) {
std::ostringstream oss;
oss << std::setprecision( 10 )
oss << std::setprecision( precision )
<< std::fixed
<< value;
std::string d = oss.str();
@ -118,6 +119,13 @@ std::string toString( const double value ) {
return d;
}
std::string toString( const double value ) {
return fpToString( value, 10 );
}
std::string toString( const float value ) {
return fpToString( value, 5 ) + "f";
}
std::string toString( bool value ) {
return value ? "true" : "false";
}