bytes_to_human_str support round off

use_iouring
YuQing 2025-09-03 15:23:27 +08:00
parent 84a1f90a9a
commit b97f23ced2
1 changed files with 23 additions and 4 deletions

View File

@ -3254,18 +3254,37 @@ const char *long2str(const int64_t n, char *buff, const bool thousands_separator
static int format_bytes_string(const int64_t input_bytes,
const int64_t unit_bytes, char *buff)
{
int64_t remain;
int n;
int fragment;
char *p;
n = input_bytes / unit_bytes;
remain = input_bytes - (n * unit_bytes);
if (n < 10)
{
fragment = (remain * 10LL + unit_bytes / 2) / unit_bytes;
if (fragment == 10)
{
++n;
fragment = 0;
}
p = buff + fc_itoa(n, buff);
if (n < 10)
{
fragment = ((input_bytes - (n * unit_bytes)) * 10LL) / unit_bytes;
*p++ = '.';
p += fc_itoa(fragment, p);
}
}
else
{
if (remain >= unit_bytes / 2)
{
++n;
}
p = buff + fc_itoa(n, buff);
}
return p - buff;
}