diff --git a/include/dsn/utility/strings.h b/include/dsn/utility/strings.h index 67057de5a9..175ce3561e 100644 --- a/include/dsn/utility/strings.h +++ b/include/dsn/utility/strings.h @@ -49,7 +49,5 @@ char *trim_string(char *s); // calculate the md5 checksum of buffer std::string string_md5(const char *buffer, unsigned int length); - -std::string to_string_with_precision(const double double_val, const int precision); } } diff --git a/src/core/core/strings.cpp b/src/core/core/strings.cpp index d538e7cd7f..a53ff2698c 100644 --- a/src/core/core/strings.cpp +++ b/src/core/core/strings.cpp @@ -183,13 +183,5 @@ std::string string_md5(const char *buffer, unsigned length) return result; } - -std::string to_string_with_precision(const double double_val, const int precision) -{ - std::ostringstream out; - out.precision(precision); - out << std::fixed << double_val; - return out.str(); -} } } diff --git a/src/dist/replication/meta_server/meta_service.cpp b/src/dist/replication/meta_server/meta_service.cpp index b8490e8ea5..3c08c94c7d 100644 --- a/src/dist/replication/meta_server/meta_service.cpp +++ b/src/dist/replication/meta_server/meta_service.cpp @@ -35,6 +35,7 @@ #include #include +#include #include #include @@ -477,9 +478,9 @@ void meta_service::on_query_cluster_info(dsn::message_ex *req) double primary_stddev, total_stddev; _state->get_cluster_balance_score(primary_stddev, total_stddev); response.keys.push_back("primary_replica_count_stddev"); - response.values.push_back(utils::to_string_with_precision(primary_stddev, 2)); + response.values.push_back(fmt::format("{:.{}f}", primary_stddev, 2)); response.keys.push_back("total_replica_count_stddev"); - response.values.push_back(utils::to_string_with_precision(total_stddev, 2)); + response.values.push_back(fmt::format("{:.{}f}", total_stddev, 2)); response.err = dsn::ERR_OK; reply(req, response);