diff options
| -rw-r--r-- | src/Fl_Valuator.cxx | 23 |
1 files changed, 15 insertions, 8 deletions
diff --git a/src/Fl_Valuator.cxx b/src/Fl_Valuator.cxx index b6065a4c8..e8431f10b 100644 --- a/src/Fl_Valuator.cxx +++ b/src/Fl_Valuator.cxx @@ -124,16 +124,23 @@ int Fl_Valuator::format(char* buffer) { // Figure out how many digits are required to correctly format the // value. - int i; - char temp[255], *ptr; - snprintf(temp, sizeof(temp), "%g", A/B); - if ((ptr = strchr(temp, '.')) != NULL) - i = strlen(ptr + 1); - else - i = 0; + int i, c = 0; + char temp[32], *ptr; + // output a number with many digits after the decimal point. This + // seems to be needed to get high precission + snprintf(temp, sizeof(temp), "%.12f", A/B); + // strip all trailing 0's + for (i=strlen(temp)-1; i>0; i--) { + if (temp[i]!='0') break; + } + // count digits until we find the decimal point (or comma or whatever + // letter is set in the current locale) + for (; i>0; i--, c++) { + if (!isdigit(temp[i])) break; + } // MRS: THIS IS A HACK - RECOMMEND ADDING BUFFER SIZE ARGUMENT - return snprintf(buffer, 128, "%.*f", i, v); + return snprintf(buffer, 128, "%.*f", c, v); } // |
