Fix tiny bug in double 2 string formatting

- I forgot to handle the trailing dots when I added the fmt variant
- UIDouble2Str (the original) lacked the comma check
- Add unit test lol
This commit is contained in:
Marek Roszko
2023-01-21 13:54:52 -05:00
parent 2b128c79f2
commit b2421c7d9f
3 changed files with 45 additions and 3 deletions
+9 -2
View File
@@ -1104,11 +1104,18 @@ std::string FormatDouble2Str( double aValue )
{
buf = fmt::format( "{:.16f}", aValue );
// remove trailing zeros
// remove trailing zeros (and the decimal marker if needed)
while( !buf.empty() && buf[buf.size() - 1] == '0' )
{
buf.pop_back();
}
// if the value was really small
// we may have just stripped all the zeros after the decimal
if( buf[buf.size() - 1] == '.' )
{
buf.pop_back();
}
}
else
{
@@ -1133,7 +1140,7 @@ std::string UIDouble2Str( double aValue )
while( --len > 0 && buf[len] == '0' )
buf[len] = '\0';
if( buf[len] == '.' )
if( buf[len] == '.' || buf[len] == ',' )
buf[len] = '\0';
else
++len;