return ctables_pcexpr_evaluate (&ctx, pc->expr);
}
+static char *
+ctables_format (double d, const struct fmt_spec *format,
+ const struct fmt_settings *settings)
+{
+ const union value v = { .f = d };
+ char *s = data_out_stretchy (&v, "UTF-8", format, settings, NULL);
+
+ /* The custom-currency specifications for NEQUAL, PAREN, and PCTPAREN don't
+ produce the results we want for negative numbers, putting the negative
+ sign in the wrong spot, before the prefix instead of after it. We can't,
+ in fact, produce the desired results using a custom-currency
+ specification. Instead, we postprocess the output, moving the negative
+ sign into place:
+
+ NEQUAL: "-N=3" => "N=-3"
+ PAREN: "-(3)" => "(-3)"
+ PCTPAREN: "-(3%)" => "(-3%)"
+
+ This transformation doesn't affect NEGPAREN. */
+ char *minus_src = strchr (s, '-');
+ if (minus_src && (minus_src == s || minus_src[-1] != 'E'))
+ {
+ char *n_equals = strstr (s, "N=");
+ char *lparen = strchr (s, '(');
+ char *minus_dst = n_equals ? n_equals + 1 : lparen;
+ if (minus_dst)
+ move_element (s, minus_dst - s + 1, 1, minus_src - s, minus_dst - s);
+ }
+ return s;
+}
+
static void
ctables_table_output (struct ctables *ct, struct ctables_table *t)
{
else if (d == SYSMIS && ct->missing)
value = pivot_value_new_user_text (ct->missing, SIZE_MAX);
else if (is_ctables_format)
- {
- char *s = data_out_stretchy (&(union value) { .f = d },
- "UTF-8", &format,
- &ct->ctables_formats, NULL);
- value = pivot_value_new_user_text_nocopy (s);
- }
+ value = pivot_value_new_user_text_nocopy (
+ ctables_format (d, &format, &ct->ctables_formats));
else
{
value = pivot_value_new_number (d);