Changeset 8015
- Timestamp:
- Mar 4, 2009, 3:37:54 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gtk/util.c
r7774 r8015 49 49 #include "util.h" 50 50 51 static void 52 printf_double_without_rounding( char * buf, int buflen, double d, int places ) 53 { 54 char * pch; 55 char tmp[128]; 56 int len; 57 g_snprintf( tmp, sizeof( tmp ), "%'.64f", d ); 58 pch = strchr( tmp, '.' ); 59 pch += places + 1; 60 len = MIN( buflen - 1, pch - tmp ); 61 memcpy( buf, tmp, len ); 62 buf[len] = '\0'; 63 } 64 51 65 char* 52 tr_strlratio( char * buf, 53 double ratio, 54 size_t buflen ) 66 tr_strlratio( char * buf, double ratio, size_t buflen ) 55 67 { 56 68 if( (int)ratio == TR_RATIO_NA ) … … 59 71 g_strlcpy( buf, "\xE2\x88\x9E", buflen ); 60 72 else if( ratio < 10.0 ) 61 g_snprintf( buf, buflen, "%'.2f", ratio);73 printf_double_without_rounding( buf, buflen, ratio, 2 ); 62 74 else if( ratio < 100.0 ) 63 g_snprintf( buf, buflen, "%'.1f", ratio);75 printf_double_without_rounding( buf, buflen, ratio, 1 ); 64 76 else 65 77 g_snprintf( buf, buflen, "%'.0f", ratio );
Note: See TracChangeset
for help on using the changeset viewer.