mirror of
https://github.com/ccxvii/mujs.git
synced 2026-09-22 07:03:36 +08:00
Fix bug in toFixed, toPrecision and toExponential.
This commit is contained in:
+3
-3
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user