If I have the code:
cv::FileStorage fs("foo.yaml", FileStorage::WRITE);
fs << "myval" << 0.6;
I end up with:
myval: 5.9999999999999998e-01
Of course, I know why floating point isn't exact, but for the sake of neatness in the file I would like to see one of:
myval: 6.00e-01
or:
myval: 0.60
A work-around is:
std::stringstream floatFormat;
floatFormat << std::fixed << std::setprecision(2) << 0.6;
fs << "myval" << floatFormat.str();
But that gives:
myval: "0.60"
Which is of string
type.
Is there any way I can force OpenCV to use a specified precision when writing values?
Note, this is a file I consume myself, so I can tweak my reading code to use std::stof()
on the fly, but it would nice to have a cleaner solution.