mirror of
https://github.com/catchorg/Catch2.git
synced 2025-05-28 15:39:27 +00:00
Format floats like doubles when printing - but add ‘f’ suffix (a lá #291)
This commit is contained in:
parent
ce56209250
commit
d89e74faff
7 changed files with 77 additions and 68 deletions
|
@ -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";
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue