mirror of
https://github.com/transmission/transmission
synced 2025-03-09 13:50:00 +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 "tr-prefs.h"
|
||||||
#include "util.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*
|
char*
|
||||||
tr_strlratio( char * buf,
|
tr_strlratio( char * buf, double ratio, size_t buflen )
|
||||||
double ratio,
|
|
||||||
size_t buflen )
|
|
||||||
{
|
{
|
||||||
if( (int)ratio == TR_RATIO_NA )
|
if( (int)ratio == TR_RATIO_NA )
|
||||||
g_strlcpy( buf, _( "None" ), buflen );
|
g_strlcpy( buf, _( "None" ), buflen );
|
||||||
else if( (int)ratio == TR_RATIO_INF )
|
else if( (int)ratio == TR_RATIO_INF )
|
||||||
g_strlcpy( buf, "\xE2\x88\x9E", buflen );
|
g_strlcpy( buf, "\xE2\x88\x9E", buflen );
|
||||||
else if( ratio < 10.0 )
|
else if( ratio < 10.0 )
|
||||||
g_snprintf( buf, buflen, "%'.2f", ratio );
|
printf_double_without_rounding( buf, buflen, ratio, 2 );
|
||||||
else if( ratio < 100.0 )
|
else if( ratio < 100.0 )
|
||||||
g_snprintf( buf, buflen, "%'.1f", ratio );
|
printf_double_without_rounding( buf, buflen, ratio, 1 );
|
||||||
else
|
else
|
||||||
g_snprintf( buf, buflen, "%'.0f", ratio );
|
g_snprintf( buf, buflen, "%'.0f", ratio );
|
||||||
return buf;
|
return buf;
|
||||||
|
|
Loading…
Add table
Reference in a new issue