Changeset 8016


Ignore:
Timestamp:
Mar 4, 2009, 4:02:50 PM (13 years ago)
Author:
charles
Message:

(trunk daemon) #1881: Displayed ratio should be truncated, not rounded

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/daemon/remote.c

    r7992 r8016  
    659659#define GIGABYTE_FACTOR ( 1024.0 * 1024.0 * 1024.0 )
    660660
     661static void
     662printf_double_without_rounding( char * buf, int buflen, double d, int places )
     663{
     664    char * pch;
     665    char tmp[128];
     666    int len;
     667    tr_snprintf( tmp, sizeof( tmp ), "%'.64f", d );
     668    pch = strchr( tmp, '.' );
     669    pch += places + 1;
     670    len = MIN( buflen - 1, pch - tmp );
     671    memcpy( buf, tmp, len );
     672    buf[len] = '\0';
     673}
     674
    661675static char*
    662676strlratio2( char * buf, double ratio, size_t buflen )
     
    667681        tr_strlcpy( buf, "Inf", buflen );
    668682    else if( ratio < 10.0 )
    669         tr_snprintf( buf, buflen, "%'.2f", ratio );
     683        printf_double_without_rounding( buf, buflen, ratio, 2 );
    670684    else if( ratio < 100.0 )
    671         tr_snprintf( buf, buflen, "%'.1f", ratio );
     685        printf_double_without_rounding( buf, buflen, ratio, 1 );
    672686    else
    673687        tr_snprintf( buf, buflen, "%'.0f", ratio );
Note: See TracChangeset for help on using the changeset viewer.