/* PSPP - a program for statistical analysis.
-   Copyright (C) 1997-9, 2000, 2006, 2009, 2011, 2012 Free Software Foundation, Inc.
+   Copyright (C) 1997-9, 2000, 2006, 2009, 2011, 2012, 2013 Free Software Foundation, Inc.
 
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
     }
 }
 
+/* Like data_out_pool(), except that for basic numeric formats (F, COMMA, DOT,
+   COLLAR, PCT, E) and custom currency formats are formatted as wide as
+   necessary to fully display the selected number of decimal places. */
+char *
+data_out_stretchy (const union value *input, const char *encoding,
+                   const struct fmt_spec *format, struct pool *pool)
+{
+  struct fmt_spec wide_format;
+
+  if (fmt_get_category (format->type) & (FMT_CAT_BASIC | FMT_CAT_CUSTOM))
+    {
+      /* XXX In the common case this wastes memory for 40 bytes of mostly
+         spaces. */
+      wide_format.type = format->type;
+      wide_format.w = 40;
+      wide_format.d = format->d;
+      format = &wide_format;
+    }
+
+  return data_out_pool (input, encoding, format, pool);
+}
+
 char *
 data_out (const union value *input, const char *encoding, const struct fmt_spec *format)
 {
 
 /* PSPP - a program for statistical analysis.
-   Copyright (C) 1997-9, 2000, 2006, 2011 Free Software Foundation, Inc.
+   Copyright (C) 1997-9, 2000, 2006, 2011, 2013 Free Software Foundation, Inc.
 
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
 
 char * data_out_pool (const union value *, const char *encoding, const struct fmt_spec *, struct pool *pool);
 
+char *data_out_stretchy (const union value *, const char *encoding, const struct fmt_spec *, struct pool *);
+
 void data_out_recode (const union value *input, const char *input_encoding,
                       const struct fmt_spec *,
                       struct string *output, const char *output_encoding);
 
 /* PSPP - a program for statistical analysis.
-   Copyright (C) 1997-9, 2000, 2006, 2009, 2010, 2011 Free Software Foundation, Inc.
+   Copyright (C) 1997-9, 2000, 2006, 2009, 2010, 2011, 2013 Free Software Foundation, Inc.
 
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
     }
 #endif
 
-  contents = data_out_pool (v, var_get_encoding (var),
-                            f != NULL ? f : var_get_print_format (var),
-                            table->container);
+  contents = data_out_stretchy (v, var_get_encoding (var),
+                                f != NULL ? f : var_get_print_format (var),
+                                table->container);
 
   table->cc[c + r * table->cf] = contents;
   table->ct[c + r * table->cf] = opt;
 #endif
 
   double_value.f = val;
-  s = data_out_pool (&double_value, C_ENCODING, &f, table->container);
+  s = data_out_stretchy (&double_value, C_ENCODING, &f, table->container);
 
   table->cc[c + r * table->cf] = s + strspn (s, " ");
   table->ct[c + r * table->cf] = opt;
 #endif
 
   double_value.f = val;
-  s = data_out_pool (&double_value, C_ENCODING, fmt, table->container);
+  s = data_out_stretchy (&double_value, C_ENCODING, fmt, table->container);
   table->cc[c + r * table->cf] = s + strspn (s, " ");
   table->ct[c + r * table->cf] = opt;
 }
 
 /* PSPPIRE - a graphical user interface for PSPP.
-   Copyright (C) 2007, 2009, 2010, 2011, 2012  Free Software Foundation
+   Copyright (C) 2007, 2009, 2010, 2011, 2012, 2013  Free Software Foundation
 
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
 {
   gchar *s;
 
-  s = data_out (&v, encoding, format);
+  s = data_out_stretchy (&v, encoding, format, NULL);
   if (fmt_is_numeric (format->type))
     g_strchug (s);
   else
 
 
 Table: Valid cases = 730; cases with missing value(s) = 0.
 Variable,Valid N,Missing N,Mean,S.E. Mean,Std Dev,Variance,Kurtosis,S.E. Kurt,Skewness,S.E. Skew,Range,Minimum,Maximum,Sum
-AVAR,730,0,31.515,.405,10.937,119.608,2.411,.181,1.345,.090,76.000,18.000,94.000,23006.00
+AVAR,730,0,31.515,.405,10.937,119.608,2.411,.181,1.345,.090,76.000,18.000,94.000,23006.000
 
 Table: AVAR
 Value Label,Value,Frequency,Percent,Valid Percent,Cum Percent
 Range,,76.000
 Minimum,,18.000
 Maximum,,94.000
-Sum,,23006.00
+Sum,,23006.000
 Percentiles,50 (Median),28
 ])
 AT_CLEANUP