Double to String conversion accuracy

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.

The same double value should still result in the same XML file though, right? Can’t you limit the precision of the floating point value from whatever source it’s coming from? Not sure I quite understand your problem yet.

My internal parameter system is using float numbers so it might get truncated somewhere along the way when I am resaving the patches.

but the result will always be the same. So why will there be nasty noise in the diffs…