Skip to content

Commit

Permalink
Fl_Valuator-derived widgets could show more digits than were
Browse files Browse the repository at this point in the history
necessary (STR #971)



git-svn-id: file:///fltk/svn/fltk/branches/branch-1.1@4487 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
  • Loading branch information
michaelrsweet committed Aug 8, 2005
1 parent a4f428d commit ff88ea3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
2 changes: 2 additions & 0 deletions CHANGES
Expand Up @@ -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)
Expand Down
18 changes: 12 additions & 6 deletions src/Fl_Valuator.cxx
Expand Up @@ -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);
}

//
Expand Down

0 comments on commit ff88ea3

Please sign in to comment.