summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael R Sweet <michael.r.sweet@gmail.com>2005-08-08 15:01:45 +0000
committerMichael R Sweet <michael.r.sweet@gmail.com>2005-08-08 15:01:45 +0000
commitff88ea3ec5c5c1162d96c95a22cf44d3f6194e52 (patch)
treec01b1731d06e72692d30ed708c453dad5e83ce7a
parenta4f428d82b63a93095bcd1338875c5ba4be8d5b5 (diff)
Fl_Valuator-derived widgets could show more digits than were
necessary (STR #971) git-svn-id: file:///fltk/svn/fltk/branches/branch-1.1@4487 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
-rw-r--r--CHANGES2
-rw-r--r--src/Fl_Valuator.cxx18
2 files changed, 14 insertions, 6 deletions
diff --git a/CHANGES b/CHANGES
index be27e90b6..7ff29a1cc 100644
--- a/CHANGES
+++ b/CHANGES
@@ -3,6 +3,8 @@ CHANGES IN FLTK 1.1.7
- Documentation fixes (STR #571, STR #648, STR #692, STR
#730, STR #744, STR #745, STR #931, STR #942, STR #960,
STR #969)
+ - Fl_Valuator-derived widgets could show more digits than
+ were necessary (STR #971)
- Fl_GIF_Image did not handle images with an incorrect
number of data bits (STR #914)
- Fixed some plastic drawing artifacts (STR #906)
diff --git a/src/Fl_Valuator.cxx b/src/Fl_Valuator.cxx
index 06965f202..b6065a4c8 100644
--- a/src/Fl_Valuator.cxx
+++ b/src/Fl_Valuator.cxx
@@ -121,13 +121,19 @@ int Fl_Valuator::format(char* buffer) {
double v = value();
// MRS: THIS IS A HACK - RECOMMEND ADDING BUFFER SIZE ARGUMENT
if (!A || !B) return snprintf(buffer, 128, "%g", v);
+
+ // Figure out how many digits are required to correctly format the
+ // value.
int i;
- double ab = A/B;
- for (i=0; i<8; i++) {
- if ((ab-floor(ab))<1e-9) break;
- ab *= 10.0;
- }
- return sprintf(buffer, "%.*f", i, v);
+ char temp[255], *ptr;
+ snprintf(temp, sizeof(temp), "%g", A/B);
+ if ((ptr = strchr(temp, '.')) != NULL)
+ i = strlen(ptr + 1);
+ else
+ i = 0;
+
+ // MRS: THIS IS A HACK - RECOMMEND ADDING BUFFER SIZE ARGUMENT
+ return snprintf(buffer, 128, "%.*f", i, v);
}
//