static const char *xt_double_format(void *src, u32 fmt, struct mempool *pool)
{
+ if(fmt & XTYPE_FMT_DBL_PREC) {
+ uint prec = fmt & ~XTYPE_FMT_DBL_PREC;
+ return mp_printf(pool, "%.*lf", prec, *(double *)src);
+ }
+
switch(fmt) {
case XTYPE_FMT_RAW:
return mp_printf(pool, "%.10lf", *(double *)src);
static const char *xt_double_parse(const char *str, void *dest, struct mempool *pool UNUSED)
{
char *endptr = NULL;
- size_t sz = strlen(str);
errno = 0;
double result = strtod(str, &endptr);
- if(endptr != str + sz) return "Could not parse double.";
+ if(*endptr != 0 || endptr == str) return "Could not parse double.";
if(errno == ERANGE) return "Could not parse double: overflow happend during parsing.";
*((double *) dest) = result;
extern const struct xtype xt_bool;
extern const struct xtype xt_double;
+
+#define XTYPE_FMT_DBL_PREC 0x40000000
+#define XTYPE_FMT_DBL_FIXED_PREC(_prec) (_prec | XTYPE_FMT_DBL_PREC)
+
#endif