Changeset 8808
- Timestamp:
- Jul 14, 2009, 8:09:46 PM (13 years ago)
- Location:
- trunk
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/cli/cli.c
r8721 r8808 236 236 tr_snprintf( buf, buflen, 237 237 "Verifying local files (%.2f%%, %.2f%% valid)", 238 100 * st->recheckProgress,239 100.0 * st->percentDone);238 tr_truncd( 100 * st->recheckProgress, 2 ), 239 tr_truncd( 100 * st->percentDone, 2 ) ); 240 240 } 241 241 else if( st->activity & TR_STATUS_DOWNLOAD ) … … 247 247 "Progress: %.1f%%, dl from %d of %d peers (%.0f KB/s), " 248 248 "ul to %d (%.0f KB/s) [%s]", 249 st->percentDone * 100.0,249 tr_truncd( 100 * st->percentDone, 1 ), 250 250 st->peersSendingToUs, 251 251 st->peersConnected, -
trunk/gtk/details.c
r8764 r8808 796 796 tr_strlsize( unver, haveUnchecked, sizeof( unver ) ); 797 797 if( haveUnchecked ) 798 g_snprintf( buf, sizeof( buf ), _( "%1$s (%2$.1f%%); %3$s Unverified" ), total, ratio, unver );798 g_snprintf( buf, sizeof( buf ), _( "%1$s (%2$.1f%%); %3$s Unverified" ), total, tr_truncd( ratio, 1 ), unver ); 799 799 else 800 g_snprintf( buf, sizeof( buf ), _( "%1$s (%2$.1f%%)" ), total, ratio);800 g_snprintf( buf, sizeof( buf ), _( "%1$s (%2$.1f%%)" ), total, tr_truncd( ratio, 1 ) ); 801 801 str = buf; 802 802 } -
trunk/gtk/file-list.c
r8729 r8808 19 19 20 20 #include <libtransmission/transmission.h> 21 #include <libtransmission/utils.h> /* tr_getRatio */22 21 23 22 #include "file-list.h" -
trunk/gtk/torrent-cell-renderer.c
r8389 r8808 12 12 13 13 #include "assert.h" 14 #include <string.h> /* strcmp */14 #include <string.h> /* strcmp() */ 15 15 #include <gtk/gtk.h> 16 16 #include <glib/gi18n.h> 17 17 #include <libtransmission/transmission.h> 18 #include <libtransmission/utils.h> /* tr_truncd() */ 18 19 #include "hig.h" 19 20 #include "icons.h" … … 62 63 tr_strlsize( buf1, haveTotal, sizeof( buf1 ) ), 63 64 tr_strlsize( buf2, torStat->sizeWhenDone, sizeof( buf2 ) ), 64 t orStat->percentDone * 100.0);65 tr_truncd( torStat->percentDone * 100.0, 2 ) ); 65 66 } 66 67 else if( !isSeed ) … … 75 76 tr_strlsize( buf1, haveTotal, sizeof( buf1 ) ), 76 77 tr_strlsize( buf2, info->totalSize, sizeof( buf2 ) ), 77 t orStat->percentComplete * 100.0,78 tr_truncd( torStat->percentComplete * 100.0, 2 ), 78 79 tr_strlsize( buf3, torStat->uploadedEver, sizeof( buf3 ) ), 79 80 tr_strlratio( buf4, torStat->ratio, sizeof( buf4 ) ) ); … … 176 177 case TR_STATUS_CHECK: 177 178 g_string_append_printf( gstr, 178 _( 179 "Verifying local data (%.1f%% tested)" ), 180 torStat->recheckProgress * 100.0 ); 179 _( "Verifying local data (%.1f%% tested)" ), 180 tr_truncd( torStat->recheckProgress * 100.0, 1 ) ); 181 181 break; 182 182 -
trunk/gtk/tr-torrent.c
r8757 r8808 30 30 31 31 #include <libtransmission/transmission.h> 32 #include <libtransmission/utils.h> /* tr_truncd() */ 32 33 33 34 #include "tr-prefs.h" … … 230 231 case TR_STATUS_CHECK_WAIT: 231 232 top = 232 g_strdup_printf( _( 233 "Waiting to verify local data (%.1f%% tested)" ), 234 st->recheckProgress * 100.0 ); 233 g_strdup_printf( _( "Waiting to verify local data (%.1f%% tested)" ), 234 tr_truncd( 100 * st->recheckProgress, 1 ) ); 235 235 break; 236 236 237 237 case TR_STATUS_CHECK: 238 238 top = 239 g_strdup_printf( _( 240 "Verifying local data (%.1f%% tested)" ), 241 st->recheckProgress * 100.0 ); 239 g_strdup_printf( _( "Verifying local data (%.1f%% tested)" ), 240 tr_truncd( 100 * st->recheckProgress, 1 ) ); 242 241 break; 243 242 -
trunk/libtransmission/utils.c
r8737 r8808 18 18 #include <ctype.h> /* isalpha, tolower */ 19 19 #include <errno.h> 20 #include <math.h> /* pow */ 20 21 #include <stdarg.h> 21 22 #include <stdio.h> … … 1326 1327 ***/ 1327 1328 1328 static void 1329 printf_double_without_rounding( char * buf, int buflen, double d, int places ) 1330 { 1331 char * pch; 1332 char tmp[128]; 1333 int len; 1334 tr_snprintf( tmp, sizeof( tmp ), "%'.64f", d ); 1335 pch = tmp; 1336 while( isdigit( *pch ) ) ++pch; /* walk to the decimal point */ 1337 ++pch; /* walk over the decimal point */ 1338 pch += places; 1339 len = MIN( buflen - 1, pch - tmp ); 1340 memcpy( buf, tmp, len ); 1341 buf[len] = '\0'; 1329 double 1330 tr_truncd( double x, int decimal_places ) 1331 { 1332 const int i = (int) pow( 10, decimal_places ); 1333 double x2 = (int)(x*i); 1334 return x2 / i; 1342 1335 } 1343 1336 … … 1350 1343 tr_strlcpy( buf, infinity, buflen ); 1351 1344 else if( ratio < 10.0 ) 1352 printf_double_without_rounding( buf, buflen, ratio, 2);1345 tr_snprintf( buf, buflen, "%.2f", tr_truncd( ratio, 2 ) ); 1353 1346 else if( ratio < 100.0 ) 1354 printf_double_without_rounding( buf, buflen, ratio, 1);1347 tr_snprintf( buf, buflen, "%.1f", tr_truncd( ratio, 1 ) ); 1355 1348 else 1356 1349 tr_snprintf( buf, buflen, "%'.0f", ratio ); -
trunk/libtransmission/utils.h
r8698 r8808 393 393 void* tr_int2ptr( int ); 394 394 395 /* truncate a double value at a given number of decimal places. 396 this can be used to prevent a printf() call from rounding up: 397 call with the decimal_places argument equal to the number of 398 decimal places in the printf()'s precision: 399 400 - printf("%.2f%%", 99.999 ) ==> "100.00%" 401 - printf("%.2f%%", tr_truncd(99.999, 2)) ==> "99.99%" 402 */ 403 double tr_truncd( double x, int decimal_places ); 404 395 405 /** 396 406 * @param buf the buffer to write the string to
Note: See TracChangeset
for help on using the changeset viewer.