Fix bug in toFixed, toPrecision and toExponential.

This commit is contained in:
Tor Andersson
2014-01-19 16:20:59 +01:00
parent fea397f56b
commit 3c58fa90c8
+3 -3
View File
@@ -37,7 +37,7 @@ static int Np_toFixed(js_State *J, int n)
js_Object *self = js_toobject(J, 0);
int width = js_tonumber(J, 1);
if (self->type != JS_CNUMBER) jsR_error(J, "TypeError");
sprintf(buf, "%*f", width, self->u.number);
sprintf(buf, "%.*f", width, self->u.number);
js_pushstring(J, buf);
return 1;
}
@@ -48,7 +48,7 @@ static int Np_toExponential(js_State *J, int n)
js_Object *self = js_toobject(J, 0);
int width = js_tonumber(J, 1);
if (self->type != JS_CNUMBER) jsR_error(J, "TypeError");
sprintf(buf, "%*e", width, self->u.number);
sprintf(buf, "%.*e", width, self->u.number);
js_pushstring(J, buf);
return 1;
}
@@ -59,7 +59,7 @@ static int Np_toPrecision(js_State *J, int n)
js_Object *self = js_toobject(J, 0);
int width = js_tonumber(J, 1);
if (self->type != JS_CNUMBER) jsR_error(J, "TypeError");
sprintf(buf, "%*g", width, self->u.number);
sprintf(buf, "%.*g", width, self->u.number);
js_pushstring(J, buf);
return 1;
}