Changeset 8015


Ignore:
Timestamp:
Mar 4, 2009, 3:37:54 PM (13 years ago)
Author:
charles
Message:

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gtk/util.c

    r7774 r8015  
    4949#include "util.h"
    5050
     51static void
     52printf_double_without_rounding( char * buf, int buflen, double d, int places )
     53{
     54    char * pch;
     55    char tmp[128];
     56    int len;
     57    g_snprintf( tmp, sizeof( tmp ), "%'.64f", d );
     58    pch = strchr( tmp, '.' );
     59    pch += places + 1;
     60    len = MIN( buflen - 1, pch - tmp );
     61    memcpy( buf, tmp, len );
     62    buf[len] = '\0';
     63}
     64
    5165char*
    52 tr_strlratio( char * buf,
    53               double ratio,
    54               size_t buflen )
     66tr_strlratio( char * buf, double ratio, size_t buflen )
    5567{
    5668    if( (int)ratio == TR_RATIO_NA )
     
    5971        g_strlcpy( buf, "\xE2\x88\x9E", buflen );
    6072    else if( ratio < 10.0 )
    61         g_snprintf( buf, buflen, "%'.2f", ratio );
     73        printf_double_without_rounding( buf, buflen, ratio, 2 );
    6274    else if( ratio < 100.0 )
    63         g_snprintf( buf, buflen, "%'.1f", ratio );
     75        printf_double_without_rounding( buf, buflen, ratio, 1 );
    6476    else
    6577        g_snprintf( buf, buflen, "%'.0f", ratio );
Note: See TracChangeset for help on using the changeset viewer.