I think I can see what you're saying. I did something akin to that elsewhere in the program (or rather a program that uses this keypad dialog.) Still, how many calculators have you used that preserve the actual number of digits? IIRC even my TI-83+ and TI-92 may not have done that (it's hard to remember having not used them for a year or two.)
But I think you still misunderstand. C++ *already* does that. Similar to what I said before if you do:
float x=10.0000, y=3.0010;
cout<<x*y;
float x=10.0000, y=3.0010;
cout<<x*y;
To copy to clipboard, switch view to plain text mode
the output will be 30.01, not 30.010 (or 30.0100), which true precision would say the result *is*. This is *default functionality* is what I'm saying; and I'm surprised that Qt went out of it's way to "improve" upon functionality without also allowing you to print it the way it would normally.
What I'm calling "useless digits" are the same digits the default truncation C++ gets rid of, however accurate it would be in real world scientific application. Note also, that your calculator would be incorrect if given two values like the above (if I understand you correctly):
float x=10, y=3.0010;
cout<<x*y;
float x=10, y=3.0010;
cout<<x*y;
To copy to clipboard, switch view to plain text mode
This would output under your code (assuming I understand you) 30.010 (or 30.0100), which is incorrect. We can only know that it is 30. Further more, if a user is using your calculator which value do they expect? They expect that you didn't get rid of their .01 for the sake of precision correctness. They'd expect it to be the "incorrect" or "unprecise" value because they're presumably either smart enough to truncate the amount they were not supposed to use, or don't care to.
I argue that in *any* user realm, the user expects the calculator to give it all of it's information and they don't want several trailing zeros. Again, in acadamia or research you'd likely go figure out the precision yourself and rather have the calculator just calculate.
Disclaimer: I hate to turn this into a topic about the philosophy of keypad precision :S. Technically my question is answered and a solution is posted.
EDIT: It's worth noting that I understand C++ isn't technically truncating digits; that instead it's never saving them in the floating point format because there's no need to. It doesn't change my point at all.
Bookmarks