Changed valueToString for floats so that zeroes after a decimal are truncated -- saves file size esp. for StyledStreamWriter which uses tabs instead of spaces.

This commit is contained in:
Christopher Dunn 2008-01-24 20:09:48 +00:00
parent 32927b0b22
commit ed971e180e

View File

@ -55,6 +55,34 @@ std::string valueToString( double value )
#else
sprintf(buffer, "%.16g", value);
#endif
char* ch = buffer + strlen(buffer) - 1;
if (*ch != '0') return buffer; // nothing to truncate, so save time
while(ch > buffer && *ch == '0'){
--ch;
}
char* last_nonzero = ch;
while(ch >= buffer){
switch(*ch){
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
--ch;
continue;
case '.':
// Truncate zeroes to save bytes in output, but keep one.
*(last_nonzero+2) = '\0';
return buffer;
default:
return buffer;
}
}
return buffer;
}