String from floating-point giving wrong number of decimal places


#1

There seems to be an issue with constructing a String from double or float with a specified number of decimal places. The parameter is being interpreted as total number of places, which means that (for example) String(2589410.5894, 7) results in “2589410”.

This is happening in the call to StackArrayStream::writeDouble(n, decPlaces), because the std::ostream defaults to treating the places parameter as total number. It can be fixed by setting a flag:
std::ostream o (this);
if (numDecPlaces > 0)
{
o.setf(std::ios_base::fixed); // this flags precision as decimal-places only
o.precision((std::streamsize) numDecPlaces);
}
:
I’m seeing this on Windows, but it appears to be general.