1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2025-02-22 06:00:41 +00:00

(trunk libT) use the Mac client's speed formatter

This commit is contained in:
Charles Kerr 2010-07-08 03:20:07 +00:00
parent 03ed3f2ca8
commit 098117c987

View file

@ -1645,7 +1645,23 @@ tr_formatter_speed_init( unsigned int kilo,
char*
tr_formatter_speed_Bps( char * buf, uint64_t bytes_per_second, size_t buflen )
{
formatter_get_size_str( &speed_units, buf, bytes_per_second, buflen );
const double K = speed_units.units[TR_FMT_KB].value;
double speed = bytes_per_second / K;
if( speed <= 999.95 ) /* 0.0 KB to 999.9 KB */
tr_snprintf( buf, buflen, "%.2f %s", speed, speed_units.units[TR_FMT_KB].name );
else {
speed /= K;
if( speed <= 99.995 ) /* 0.98 MB to 99.99 MB */
tr_snprintf( buf, buflen, "%.2f %s", speed, speed_units.units[TR_FMT_MB].name );
else if (speed <= 999.95) /* 100.0 MB to 999.9 MB */
tr_snprintf( buf, buflen, "%.1f %s", speed, speed_units.units[TR_FMT_MB].name );
else {
speed /= K;
tr_snprintf( buf, buflen, "%.1f %s", speed, speed_units.units[TR_FMT_GB].name );
}
}
return buf;
}