Changeset 11252


Ignore:
Timestamp:
Sep 22, 2010, 4:09:36 PM (11 years ago)
Author:
charles
Message:

(trunk libT) #3521 "rounding issue in tr_truncd()" -- fixed.

Location:
trunk/libtransmission
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/utils-test.c

    r11049 r11252  
    390390    check( !strcmp( buf, "403650.6562" ) );
    391391
     392    tr_snprintf( buf, sizeof( buf ), "%.2f", tr_truncd( 2.15, 2 ) );
     393    check( !strcmp( buf, "2.15" ) );
     394
    392395    return 0;
    393396}
  • trunk/libtransmission/utils.c

    r11250 r11252  
    13861386tr_truncd( double x, int decimal_places )
    13871387{
    1388     const int i = (int) pow( 10, decimal_places ); 
    1389     const double x2 = (int64_t)(x * i);
     1388    const int i = (int) pow( 10, decimal_places );
     1389    const double xup = x * i;
     1390    const double x2 = (int64_t)(xup);
    13901391    return x2 / i;
    13911392}
     
    13951396{
    13961397    tr_snprintf( buf, buflen, "%.*f", precision, tr_truncd( x, precision ) );
    1397 
    13981398    return buf;
    13991399}
Note: See TracChangeset for help on using the changeset viewer.