diff options
| author | Matthias Melcher <fltk@matthiasm.com> | 2005-03-08 22:55:10 +0000 |
|---|---|---|
| committer | Matthias Melcher <fltk@matthiasm.com> | 2005-03-08 22:55:10 +0000 |
| commit | 2bbee87dc306d6beeb8f0a0a4bd3b6092eb6eee5 (patch) | |
| tree | edb607060ca645f80c13ab22bfa35f73ebd4db8a /src/Fl_Valuator.cxx | |
| parent | 29e022cc46b35da484592af581a1c16bfd5f1530 (diff) | |
'Anonymous' reported a problem when using Fl_Value_Input. It seemed,
that contrary to the man pages, a fractional 'step' value above 1
would not create a floating point input.
In fact it does, but the output was formatted wrong so that the
digits after the decimal point were never rendered.
I changed the Fl_Valuator::format(double v) function how I beleive
it should format the output correctly, but as already stated by
the original author in the source code, this is a hack that should
be fixed by providing a 'precission' setting for valuators.
Anyway. My fix makes sure that all digits right of the decimal
point are always rendered, so that the step value will show full
precision. This gives a much better behavior in respect to steps values
like 2.5, 3.75, etc., but also leads to 8 digits after the decimal point
for step(1.0/3.0)... .
I suggest that we keep this change (hence the commit), risking that
rendering of valuator text will change in a few cases (odd step() values).
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.1@4091 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
Diffstat (limited to 'src/Fl_Valuator.cxx')
| -rw-r--r-- | src/Fl_Valuator.cxx | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/src/Fl_Valuator.cxx b/src/Fl_Valuator.cxx index b3837f1a6..4e83bf5de 100644 --- a/src/Fl_Valuator.cxx +++ b/src/Fl_Valuator.cxx @@ -118,10 +118,13 @@ double Fl_Valuator::increment(double v, int n) { int Fl_Valuator::format(char* buffer) { double v = value(); // MRS: THIS IS A HACK - RECOMMEND ADDING BUFFER SIZE ARGUMENT - if (!A) return snprintf(buffer, 128, "%g", v); - int i, X; - double ba = B / A; - for (X = 1, i = 0; X < ba; X *= 10) i++; + if (!A || !B) return snprintf(buffer, 128, "%g", v); + 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); } |
