Skip to content

Commit 0803dfb

Browse files
committed
get_pretty_str_from_float replaced with get_pretty_str_from_double to not lose precision
1 parent 55b2aa8 commit 0803dfb

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

vpr/src/server/convertutils.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ std::optional<int> try_convert_to_int(const std::string& str) {
1616
}
1717
}
1818

19-
static std::string get_pretty_str_from_float(float value) {
19+
static std::string get_pretty_str_from_double(double value) {
2020
std::ostringstream ss;
2121
ss << std::fixed << std::setprecision(2) << value; // Set precision to 2 digit after the decimal point
2222
return ss.str();
@@ -25,7 +25,7 @@ static std::string get_pretty_str_from_float(float value) {
2525
std::string get_pretty_duration_str_from_ms(int64_t duration_ms) {
2626
std::string result;
2727
if (duration_ms >= 1000) {
28-
result = get_pretty_str_from_float(duration_ms / 1000.0f) + " sec";
28+
result = get_pretty_str_from_double(duration_ms / 1000.0) + " sec";
2929
} else {
3030
result = std::to_string(duration_ms);
3131
result += " ms";
@@ -36,11 +36,11 @@ std::string get_pretty_duration_str_from_ms(int64_t duration_ms) {
3636
std::string get_pretty_size_str_from_bytes_num(int64_t bytes_num) {
3737
std::string result;
3838
if (bytes_num >= 1024*1024*1024) {
39-
result = get_pretty_str_from_float(bytes_num / float(1024*1024*1024)) + "Gb";
39+
result = get_pretty_str_from_double(bytes_num / double(1024*1024*1024)) + "Gb";
4040
} else if (bytes_num >= 1024*1024) {
41-
result = get_pretty_str_from_float(bytes_num / float(1024*1024)) + "Mb";
41+
result = get_pretty_str_from_double(bytes_num / double(1024*1024)) + "Mb";
4242
} else if (bytes_num >= 1024) {
43-
result = get_pretty_str_from_float(bytes_num / float(1024)) + "Kb";
43+
result = get_pretty_str_from_double(bytes_num / double(1024)) + "Kb";
4444
} else {
4545
result = std::to_string(bytes_num) + "bytes";
4646
}

0 commit comments

Comments
 (0)