From f3460eaea0e80a33ef6fce60ecd5eacc70a16560 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Sun, 17 Oct 2010 18:27:42 +0000 Subject: [PATCH] (trunk libT) #3521 "rounding issue in tr_truncd()" -- this time for sure... --- libtransmission/utils.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/libtransmission/utils.c b/libtransmission/utils.c index 1c937ab14..1d621c3f3 100644 --- a/libtransmission/utils.c +++ b/libtransmission/utils.c @@ -1433,8 +1433,12 @@ tr_parseNumberRange( const char * str_in, int len, int * setmeCount ) double tr_truncd( double x, int decimal_places ) { + /* sigh... surely there's a better way to do this */ + char buf[1024]; const int i = (int) pow( 10, decimal_places ); - return floor( x * i ) / i; + snprintf( buf, sizeof( buf ), "%f", x*i ); + *strchr(buf,'.') = '\0'; + return atof(buf) / i; } char*