mirror of
https://github.com/fltk/fltk.git
synced 2026-05-25 09:17:49 +08:00
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
This commit is contained in:
@@ -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)
|
||||
|
||||
+12
-6
@@ -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);
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
Reference in New Issue
Block a user