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 02c658abe3a3..28251b458a7d 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,9 @@ DataSize::DataSize(const std::string& string) { } std::string DataSize::toString() const { - char buffer[32]; - snprintf( - buffer, - sizeof(buffer), - "%f%s", - round(value_ * 100.0) / 100.0, - dataUnitToString(dataUnit_).c_str()); - return std::string(buffer); + return fmt::format( + "{:f}{}", round(value_ * 100.0) / 100.0, 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 e6bdce620867..fa5c94057721 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,7 @@ Duration::Duration(const std::string& duration) { } std::string Duration::toString() const { - char buffer[32]; - snprintf( - buffer, - sizeof(buffer), - "%.2f%s", - value_, - timeUnitToString(timeUnit_).c_str()); - return std::string(buffer); + return fmt::format("{:.2f}{}", value_, timeUnitToString(timeUnit_)); } double Duration::toMillisPerTimeUnit(TimeUnit timeUnit) {