mirror of
https://github.com/transmission/transmission
synced 2025-02-18 20:30:43 +00:00
(trunk libT) #3521 "rounding issue in tr_truncd()" -- fixed.
This commit is contained in:
parent
70933cfae1
commit
b63d64e0e3
2 changed files with 6 additions and 3 deletions
|
@ -389,6 +389,9 @@ test_truncd( void )
|
|||
tr_snprintf( buf, sizeof( buf ), "%.4f", tr_truncd( 403650.656250, 4 ) );
|
||||
check( !strcmp( buf, "403650.6562" ) );
|
||||
|
||||
tr_snprintf( buf, sizeof( buf ), "%.2f", tr_truncd( 2.15, 2 ) );
|
||||
check( !strcmp( buf, "2.15" ) );
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -1385,8 +1385,9 @@ tr_parseNumberRange( const char * str_in, int len, int * setmeCount )
|
|||
double
|
||||
tr_truncd( double x, int decimal_places )
|
||||
{
|
||||
const int i = (int) pow( 10, decimal_places );
|
||||
const double x2 = (int64_t)(x * i);
|
||||
const int i = (int) pow( 10, decimal_places );
|
||||
const double xup = x * i;
|
||||
const double x2 = (int64_t)(xup);
|
||||
return x2 / i;
|
||||
}
|
||||
|
||||
|
@ -1394,7 +1395,6 @@ char*
|
|||
tr_strtruncd( char * buf, double x, int precision, size_t buflen )
|
||||
{
|
||||
tr_snprintf( buf, buflen, "%.*f", precision, tr_truncd( x, precision ) );
|
||||
|
||||
return buf;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue