mirror of
https://github.com/transmission/transmission
synced 2025-03-06 19:48:15 +00:00
(trunk gtk) #1881: Displayed ratio should be truncated, not rounded
This commit is contained in:
parent
e8422f8cdd
commit
c2fc713111
1 changed files with 17 additions and 5 deletions
22
gtk/util.c
22
gtk/util.c
|
@ -48,19 +48,31 @@
|
|||
#include "tr-prefs.h"
|
||||
#include "util.h"
|
||||
|
||||
static void
|
||||
printf_double_without_rounding( char * buf, int buflen, double d, int places )
|
||||
{
|
||||
char * pch;
|
||||
char tmp[128];
|
||||
int len;
|
||||
g_snprintf( tmp, sizeof( tmp ), "%'.64f", d );
|
||||
pch = strchr( tmp, '.' );
|
||||
pch += places + 1;
|
||||
len = MIN( buflen - 1, pch - tmp );
|
||||
memcpy( buf, tmp, len );
|
||||
buf[len] = '\0';
|
||||
}
|
||||
|
||||
char*
|
||||
tr_strlratio( char * buf,
|
||||
double ratio,
|
||||
size_t buflen )
|
||||
tr_strlratio( char * buf, double ratio, size_t buflen )
|
||||
{
|
||||
if( (int)ratio == TR_RATIO_NA )
|
||||
g_strlcpy( buf, _( "None" ), buflen );
|
||||
else if( (int)ratio == TR_RATIO_INF )
|
||||
g_strlcpy( buf, "\xE2\x88\x9E", buflen );
|
||||
else if( ratio < 10.0 )
|
||||
g_snprintf( buf, buflen, "%'.2f", ratio );
|
||||
printf_double_without_rounding( buf, buflen, ratio, 2 );
|
||||
else if( ratio < 100.0 )
|
||||
g_snprintf( buf, buflen, "%'.1f", ratio );
|
||||
printf_double_without_rounding( buf, buflen, ratio, 1 );
|
||||
else
|
||||
g_snprintf( buf, buflen, "%'.0f", ratio );
|
||||
return buf;
|
||||
|
|
Loading…
Add table
Reference in a new issue