diff --git a/src/string_util.cc b/src/string_util.cc index 4cefbfba..cd4e7cfd 100644 --- a/src/string_util.cc +++ b/src/string_util.cc @@ -45,6 +45,8 @@ void ToExponentAndMantissa(double val, double thresh, int precision, std::max(thresh, 1.0 / std::pow(10.0, precision)); const double big_threshold = adjusted_threshold * one_k; const double small_threshold = adjusted_threshold; + // Values in ]simple_threshold,small_threshold[ will be printed as-is + const double simple_threshold = 0.01; if (val > big_threshold) { // Positive powers @@ -62,14 +64,16 @@ void ToExponentAndMantissa(double val, double thresh, int precision, *exponent = 0; } else if (val < small_threshold) { // Negative powers - double scaled = val; - for (size_t i = 0; i < arraysize(kSmallSIUnits); ++i) { - scaled *= one_k; - if (scaled >= small_threshold) { - mantissa_stream << scaled; - *exponent = -static_cast<int64_t>(i + 1); - *mantissa = mantissa_stream.str(); - return; + if (val < simple_threshold) { + double scaled = val; + for (size_t i = 0; i < arraysize(kSmallSIUnits); ++i) { + scaled *= one_k; + if (scaled >= small_threshold) { + mantissa_stream << scaled; + *exponent = -static_cast<int64_t>(i + 1); + *mantissa = mantissa_stream.str(); + return; + } } } mantissa_stream << val;