MCPcopy Create free account
hub / github.com/ChaiScript/ChaiScript / fpToString

Function fpToString

unittests/catch.hpp:10642–10659  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

10640
10641template<typename T>
10642std::string fpToString( T value, int precision ) {
10643 if (std::isnan(value)) {
10644 return "nan";
10645 }
10646
10647 ReusableStringStream rss;
10648 rss << std::setprecision( precision )
10649 << std::fixed
10650 << value;
10651 std::string d = rss.str();
10652 std::size_t i = d.find_last_not_of( '0' );
10653 if( i != std::string::npos && i != d.size()-1 ) {
10654 if( d[i] == '.' )
10655 i++;
10656 d = d.substr( 0, i+1 );
10657 }
10658 return d;
10659}
10660
10661//// ======================================================= ////
10662//

Callers 1

convertMethod · 0.85

Calls 3

substrMethod · 0.80
strMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected