String fiddling
Hi,
I am looking for the a compact way of removing superfluous right hand zeros in C++. The task at hand is (double) numerical user input from a listbox. I want to first validiate the number (no problem with that) and then echo a possibly corrected value to the list box.
1) Only significant fractional digits should be shown; i.e right hand side zeros should be suppressed.
2) The number of significant fractional digits should be allowed to increase up to some max number.
3) If the user input from the list box contains more than the allowed number of fractional digits the echoed number should be rounded off (not truncated) to the max allowed fractional digits.
Although the necessary code isn't that complicated, it tend to be a bit long winded when all necessaray error checking is included. Hence, if anybody out there knows about a snipped that performs the above task, I would be interesting in having a look at it.
Regards
Udo.
|