Hi everybody,
I need to store floating point numbers that come from a var into a XML file and make it available for source control (git).
The problem is that the internal floating point type for vars is double, so it generates pretty random digits beyond the float accuracy (if it the var was created from a floating point number which is the case in my scenario) and this introduces nasty noise for diffs of the XML files.
I solved this by adding a macro called DOUBLE_TO_STRING_DIGITS, which defaults to 20, but can be set to 8 if you don’t need double accuracy. You can then change this method from the var::VariantType_Double class to take that number into account:
String toString (const ValueUnion& data) const override { return String (data.doubleValue, DOUBLE_TO_STRING_DIGITS); }
It’s pretty hacky (and it certainly won’t meet the holy JUCE coding standards), but if this is a reasonable request, it would be great if this (or a better solution) found a way into the official code base so I don’t have to patch it every time I update the JUCE version.