pspp-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[sheet-prep-2 2/3] format: Use max width for over-max decimals in fmt_fi


From: Ben Pfaff
Subject: [sheet-prep-2 2/3] format: Use max width for over-max decimals in fmt_fix().
Date: Tue, 12 Jul 2011 22:21:48 -0700

In fmt_fix(), requesting more decimals than are possible did
not increase the width at all.  It makes better sense to use
the maximum width and maximum decimals for this case, so this
commit makes that change.
---
 src/data/format.c |   19 ++++++++-----------
 1 files changed, 8 insertions(+), 11 deletions(-)

diff --git a/src/data/format.c b/src/data/format.c
index 559ab66..3c407f4 100644
--- a/src/data/format.c
+++ b/src/data/format.c
@@ -516,18 +516,15 @@ fmt_fix (struct fmt_spec *fmt, bool for_input)
   step = fmt_step_width (fmt->type);
   fmt->w = ROUND_DOWN (fmt->w, step);
 
-  /* First, if FMT has more decimal places than allowed, attempt
-     to increase FMT's width until that number of decimal places
-     can be achieved. */
-  if (fmt->d > fmt_max_decimals (fmt->type, fmt->w, for_input))
+  /* If FMT has more decimal places than allowed, attempt to increase FMT's
+     width until that number of decimal places can be achieved. */
+  if (fmt->d > fmt_max_decimals (fmt->type, fmt->w, for_input)
+      && fmt_takes_decimals (fmt->type))
     {
-      int w;
-      for (w = fmt->w; w <= max_w; w++)
-        if (fmt_max_decimals (fmt->type, w, for_input) >= fmt->d)
-          {
-            fmt->w = w;
-            break;
-          }
+      int max_w = fmt_max_width (fmt->type, for_input);
+      for (; fmt->w < max_w; fmt->w++)
+        if (fmt->d <= fmt_max_decimals (fmt->type, fmt->w, for_input))
+          break;
     }
 
   /* Clamp decimals to those allowed by format and width. */
-- 
1.7.2.5




reply via email to

[Prev in Thread] Current Thread [Next in Thread]