MCPcopy Create free account
hub / github.com/RangeNetworks/openbts / fmtfloat2

Function fmtfloat2

GPRS/MSInfo.cpp:965–978  ·  view source on GitHub ↗

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.

Source from the content-addressed store, hash-verified

963// but dont go less than .01 or to exponential notation.
964// Kind of amazing there is no default format for this.
965std::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
981static void putER(std::ostream&os, const char*label, float er, int total)

Callers 3

putERFunction · 0.85
msDumpMethod · 0.85
mchDumpMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected