How to print double with all decimals in Qt?

Viewed 10156

First of all this is no duplicate. I searched the web but no answer is sufficient.

I want to print a double. So I have to convert it to a QString. I want to have no scientific notation and 0.1 should print 0.1 and 1/3 should print as much 0.33333... as double is capable to represent. Unfortunately I can find only solutions with fixed precision, which leads to eiter a capped 0.333333 (end after specified p loosing precision) or an unnecessary zero filled 0.100000.

I know I could max out the precision and drop all trailing zeroes, but isnt there a nice solution, which just prints max possible but min necessary precision?

Edit: I guess I need to clearify a few things. This question is not about to map the space of real numbers into single, double or whatever precision floating point numbers. It is about the inverse: the mapping of the 64 bit double precision floating point space into our beloved realworld real numbers. Since the former is a subset of the latter there is, in theory, absolutely no problem doing this.

2 Answers
Related