1
0
forked from GitHub/gf-core

locale independent printing for doubles when they are part of an abstract expression

This commit is contained in:
krasimir
2016-04-13 14:30:40 +00:00
parent c0344e936a
commit e8e52de6b9
3 changed files with 27 additions and 1 deletions

View File

@@ -217,6 +217,29 @@ gu_string_to_double(GuString s, double *res)
return true; return true;
} }
void
gu_double_to_string(double val, GuOut* out, GuExn* err)
{
int ival = (int) val;
gu_printf(out, err, "%d", ival);
val -= ival;
if (val < 0)
val = -val;
if (val != 0) {
gu_putc('.', out, err);
while (val > 0.000001) // process remaining digits
{
val = val * 10;
ival = (int) val;
gu_printf(out, err, "%d", ival);
val -= ival;
}
}
}
bool bool
gu_string_is_prefix(GuString s1, GuString s2) gu_string_is_prefix(GuString s1, GuString s2)
{ {

View File

@@ -48,6 +48,9 @@ gu_string_to_int(GuString s, int *res);
bool bool
gu_string_to_double(GuString s, double *res); gu_string_to_double(GuString s, double *res);
void
gu_double_to_string(double val, GuOut* out, GuExn* err);
bool bool
gu_string_is_prefix(GuString s1, GuString s2); gu_string_is_prefix(GuString s1, GuString s2);

View File

@@ -1189,7 +1189,7 @@ pgf_print_literal(PgfLiteral lit,
} }
case PGF_LITERAL_FLT: { case PGF_LITERAL_FLT: {
PgfLiteralFlt* lit = ei.data; PgfLiteralFlt* lit = ei.data;
gu_printf(out, err, "%lg", lit->val); gu_double_to_string(lit->val, out, err);
break; break;
} }
default: default: