#include "str.h"
#include "var.h"
+#include "gettext.h"
+#define _(msgid) gettext (msgid)
+
#include "debug-print.h"
\f
/* Public functions. */
/* Converts binary value V into printable form in the exactly
FP->W character in buffer S according to format specification
FP. No null terminator is appended to the buffer. */
-void
+bool
data_out (char *s, const struct fmt_spec *fp, const union value *v)
{
int cat = formats[fp->type].cat;
{
memset (s, ' ', fp->w);
s[fp->w - fp->d - 1] = '.';
- return;
+ return true;
}
/* Handle decimal shift. */
/* Error handling. */
if (!ok)
strncpy (s, "ERROR", fp->w);
+
+ return ok;
}
/* Converts V into S in F format with width W and D decimal places,
static int
try_CCx (char *dst, const struct fmt_spec *fp, double number)
{
- const struct set_cust_currency *cc = get_cc(fp->type - FMT_CCA);
+ const struct custom_currency *cc = get_cc(fp->type - FMT_CCA);
struct fmt_spec f;
/* Determine length available, decimal character for number
proper. */
- f.type = cc->decimal == get_decimal() ? FMT_COMMA : FMT_DOT;
+ f.type = cc->decimal == get_decimal () ? FMT_COMMA : FMT_DOT;
f.w = fp->w - strlen (cc->prefix) - strlen (cc->suffix);
if (number < 0)
f.w -= strlen (cc->neg_prefix) + strlen (cc->neg_suffix) - 1;
sprintf (buf, "%.*f", decimals, number);
+ /* Omit integer part if it's 0. */
if (!memcmp (buf, "0.", 2))
memmove (buf, buf + 1, strlen (buf));
else if (!memcmp (buf, "-0.", 3))
}
}
+ /* Omit `-' if value output is zero. */
+ if (buf[0] == '-' && buf[strspn (buf, "-.0")] == '\0')
+ memmove (buf, buf + 1, strlen (buf));
+
buf_copy_str_lpad (dst, fp->w, buf);
return 1;
}