Format a number with up to 2 significant digits if < 1, but dont go less than .01 or to exponential notation. Kind of amazing there is no default format for this.
| 963 | // but dont go less than .01 or to exponential notation. |
| 964 | // Kind of amazing there is no default format for this. |
| 965 | std::string fmtfloat2(float num) |
| 966 | { |
| 967 | if (num < 0.005) { // < 0.01 is 0 |
| 968 | return string("0"); |
| 969 | } else if (num < 0.2) { // .01 - .19, 2 sig digit |
| 970 | return format("%.2f",num).substr(1); |
| 971 | } else if (num < 1) { // .2 - .9, 1 sig digit ok. |
| 972 | return format("%.1f",num).substr(1); |
| 973 | } else if (num < 10) { // 1.0 - 9.9, 2 sig digit |
| 974 | return format("%.1f",num); |
| 975 | } else { // 10 - infinity, whatever digits needed. |
| 976 | return format("%.0f",num); |
| 977 | } |
| 978 | } |
| 979 | |
| 980 | |
| 981 | static void putER(std::ostream&os, const char*label, float er, int total) |