diff --git a/presto-native-execution/presto_cpp/presto_protocol/core/DataSize.cpp b/presto-native-execution/presto_cpp/presto_protocol/core/DataSize.cpp index 02c658abe3a35..afd089595b500 100644 --- a/presto-native-execution/presto_cpp/presto_protocol/core/DataSize.cpp +++ b/presto-native-execution/presto_cpp/presto_protocol/core/DataSize.cpp @@ -12,6 +12,7 @@ * limitations under the License. */ #include "presto_cpp/presto_protocol/core/DataSize.h" +#include #include namespace facebook::presto::protocol { @@ -29,16 +30,12 @@ DataSize::DataSize(const std::string& string) { } std::string DataSize::toString() const { - char buffer[32]; - snprintf( - buffer, - sizeof(buffer), - "%f%s", + return fmt::format( + "{:-f}{}", round(value_ * 100.0) / 100.0, - dataUnitToString(dataUnit_).c_str()); - return std::string(buffer); + dataUnitToString(dataUnit_) + ); } - double DataSize::toBytesPerDataUnit(DataUnit dataUnit) { switch (dataUnit) { case DataUnit::BYTE: diff --git a/presto-native-execution/presto_cpp/presto_protocol/core/Duration.cpp b/presto-native-execution/presto_cpp/presto_protocol/core/Duration.cpp index e6bdce6208677..720f5b64be036 100644 --- a/presto-native-execution/presto_cpp/presto_protocol/core/Duration.cpp +++ b/presto-native-execution/presto_cpp/presto_protocol/core/Duration.cpp @@ -12,6 +12,7 @@ * limitations under the License. */ #include "presto_cpp/presto_protocol/core/Duration.h" +#include namespace facebook::presto::protocol { @@ -27,14 +28,11 @@ Duration::Duration(const std::string& duration) { } std::string Duration::toString() const { - char buffer[32]; - snprintf( - buffer, - sizeof(buffer), - "%.2f%s", + return fmt::format( + "{:.2f}{}", value_, - timeUnitToString(timeUnit_).c_str()); - return std::string(buffer); + timeUnitToString(timeUnit_) + ); } double Duration::toMillisPerTimeUnit(TimeUnit timeUnit) {