I have three sets of numbers, a measurement (which is in the range 0-1 inclusive) two errors (positive and negative. These numbers should be displayed consistently to the number of significant figures, rounded up, which corresponds to the first non-zero entry in either of the number.
This requirement is skipped on the measurement if it is one (i.e. only the figures in the errors need be considered). For example:
0.95637 (+0.00123, -0.02935) --> 0.96 +0.00 -0.03
1.00000 (+0.0, -0.0979) --> 1.0 +0.0 -0.1 (note had to truncate due to -ve error rounding up at first significant digit)
Now, getting at the first non-zero digit is easy by taking log10(num), but I'm having an idiotic moment trying to get stripping and rounding working in a clean fashion.
All data types are doubles, and language of choice is C++. All and any ideas welcome!