Ignore:
Timestamp:
Jun 22, 2010, 10:30:58 PM (13 years ago)
Author:
Longinus00
Message:

#3298:Prettier formating of percentages

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/utils.c

    r10819 r10822  
    13661366
    13671367char*
     1368tr_strpercent( char * buf, double x, size_t buflen )
     1369{
     1370    if( x < 10.0 )
     1371        tr_strtruncd( buf, x, 2, buflen );
     1372    else if( x < 100.0 )
     1373        tr_strtruncd( buf, x, 1, buflen );
     1374    else
     1375        tr_strtruncd( buf, x, 0, buflen );
     1376    return buf;
     1377}
     1378
     1379char*
    13681380tr_strratio( char * buf, size_t buflen, double ratio, const char * infinity )
    13691381{
     
    13721384    else if( (int)ratio == TR_RATIO_INF )
    13731385        tr_strlcpy( buf, infinity, buflen );
    1374     else if( ratio < 10.0 )
    1375         tr_snprintf( buf, buflen, "%.2f", tr_truncd( ratio, 2 ) );
    1376     else if( ratio < 100.0 )
    1377         tr_snprintf( buf, buflen, "%.1f", tr_truncd( ratio, 1 ) );
    13781386    else
    1379         tr_snprintf( buf, buflen, "%'.0f", ratio );
     1387        tr_strpercent( buf, ratio, buflen );
     1388    return buf;
     1389}
     1390
     1391char*
     1392tr_strtruncd( char * buf, double x, int precision, size_t buflen )
     1393{
     1394    tr_snprintf( buf, buflen, "%.*f", precision, tr_truncd( x, precision ) );
     1395
    13801396    return buf;
    13811397}
Note: See TracChangeset for help on using the changeset viewer.