digitalmars.D - Precision of double in toJSON(and in general)
- Idan Arye (13/13) Feb 24 2016 http://dpaste.dzfl.pl/9a0569b20756
http://dpaste.dzfl.pl/9a0569b20756 toJSON is converting to the default precision, that fits `float`, even though the actual type is `double`. In general, printing `double` with "%s" fits `float` more than `double`. The problem, as I understand it, is that "%s" is converted to "%g" instead of "%f" for both `float`s and `double`s. I assume that's because "%f" is always printed in fixed-point format, while "%g" can choose between the fixed-point and the scientific formats. This is all well for regular printing, but when converting to JSON we needlessly lose precision. Wouldn't it be better to convert to JSON using "%f", or to generally increase the precision of `double` when using "%s"?
Feb 24 2016