Skip to content
Snippets Groups Projects
Commit f9843118 authored by rswindell's avatar rswindell
Browse files

Add a precision argument to byte_estimate_to_str() so the caller can control

the number of decimal places in the resulting string.
parent 6ce7276c
No related branches found
No related tags found
No related merge requests found
...@@ -311,16 +311,16 @@ char* DLLCALL byte_count_to_str(int64_t bytes, char* str, size_t size) ...@@ -311,16 +311,16 @@ char* DLLCALL byte_count_to_str(int64_t bytes, char* str, size_t size)
This function also appends 'B' for exact byte counts (< 1024). This function also appends 'B' for exact byte counts (< 1024).
'unit' is the smallest divisor used. 'unit' is the smallest divisor used.
*/ */
char* DLLCALL byte_estimate_to_str(int64_t bytes, char* str, size_t size, ulong unit) char* DLLCALL byte_estimate_to_str(int64_t bytes, char* str, size_t size, ulong unit, int precision)
{ {
if(bytes >= one_tebibyte) if(bytes >= one_tebibyte)
safe_snprintf(str, size, "%1.1fT", bytes/one_tebibyte); safe_snprintf(str, size, "%1.*fT", precision, bytes/one_tebibyte);
else if(bytes >= one_gibibyte || unit == one_gibibyte) else if(bytes >= one_gibibyte || unit == one_gibibyte)
safe_snprintf(str, size, "%1.1fG", bytes/one_gibibyte); safe_snprintf(str, size, "%1.*fG", precision, bytes/one_gibibyte);
else if(bytes >= one_mebibyte || unit == one_mebibyte) else if(bytes >= one_mebibyte || unit == one_mebibyte)
safe_snprintf(str, size, "%1.1fM", bytes/one_mebibyte); safe_snprintf(str, size, "%1.*fM", precision, bytes/one_mebibyte);
else if(bytes >= one_kibibyte || unit == one_kibibyte) else if(bytes >= one_kibibyte || unit == one_kibibyte)
safe_snprintf(str, size, "%1.1fK", bytes/one_kibibyte); safe_snprintf(str, size, "%1.*fK", precision, bytes/one_kibibyte);
else else
safe_snprintf(str, size, "%"PRIi64"B", bytes); safe_snprintf(str, size, "%"PRIi64"B", bytes);
......
...@@ -374,7 +374,7 @@ DLLEXPORT double DLLCALL parse_duration(const char*); ...@@ -374,7 +374,7 @@ DLLEXPORT double DLLCALL parse_duration(const char*);
DLLEXPORT char* DLLCALL duration_to_str(double value, char* str, size_t size); DLLEXPORT char* DLLCALL duration_to_str(double value, char* str, size_t size);
DLLEXPORT char* DLLCALL duration_to_vstr(double value, char* str, size_t size); DLLEXPORT char* DLLCALL duration_to_vstr(double value, char* str, size_t size);
DLLEXPORT char* DLLCALL byte_count_to_str(int64_t bytes, char* str, size_t size); DLLEXPORT char* DLLCALL byte_count_to_str(int64_t bytes, char* str, size_t size);
DLLEXPORT char* DLLCALL byte_estimate_to_str(int64_t bytes, char* str, size_t size, ulong unit); DLLEXPORT char* DLLCALL byte_estimate_to_str(int64_t bytes, char* str, size_t size, ulong unit, int precision);
/* Microsoft (e.g. DOS/Win32) real-time system clock API (ticks since process started) */ /* Microsoft (e.g. DOS/Win32) real-time system clock API (ticks since process started) */
typedef clock_t msclock_t; typedef clock_t msclock_t;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment