diff --git a/include/fc/string.hpp b/include/fc/string.hpp index b0303ef..0ae999b 100644 --- a/include/fc/string.hpp +++ b/include/fc/string.hpp @@ -16,6 +16,7 @@ namespace fc fc::string to_string( uint64_t ); fc::string to_string( int64_t ); fc::string to_string( uint16_t ); + std::string to_pretty_string( int64_t ); inline fc::string to_string( int32_t v ) { return to_string( int64_t(v) ); } inline fc::string to_string( uint32_t v ){ return to_string( uint64_t(v) ); } #ifdef __APPLE__ diff --git a/src/string.cpp b/src/string.cpp index ea5bbab..0c49a95 100644 --- a/src/string.cpp +++ b/src/string.cpp @@ -5,12 +5,28 @@ #include #include +#include /** * Implemented with std::string for now. */ namespace fc { + class comma_numpunct : public std::numpunct + { + protected: + virtual char do_thousands_sep() const { return ','; } + virtual std::string do_grouping() const { return "\03"; } + }; + + std::string to_pretty_string( int64_t value ) + { + std::stringstream ss; + ss.imbue( {std::locale(), new comma_numpunct} ); + ss << std::fixed << value; + return ss.str(); + } + #ifdef USE_FC_STRING string::string(const char* s, int l) :my(s,l){ } string::string(){}