From 9de9c353ac5c09546fba139f3f446e62522e49a5 Mon Sep 17 00:00:00 2001 From: Jacek Caban Date: Mon, 17 Dec 2012 13:35:54 +0100 Subject: [PATCH] jscript: Fixed Number.toFixed for value 0 with 0 precision. --- dlls/jscript/number.c | 6 ++++-- dlls/jscript/tests/api.js | 8 ++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/dlls/jscript/number.c b/dlls/jscript/number.c index ed773a32497..351e9153194 100644 --- a/dlls/jscript/number.c +++ b/dlls/jscript/number.c @@ -99,15 +99,17 @@ static inline jsstr_t *number_to_fixed(double val, int prec) jsstr_t *ret; WCHAR *str; + TRACE("%lf %d\n", val, prec); + if(val < 0) { neg = TRUE; val = -val; } - if(val<=-1 || val>=1) + if(val >= 1) buf_size = log10(val)+prec+2; else - buf_size = prec+1; + buf_size = prec ? prec+1 : 2; if(buf_size > NUMBER_DTOA_SIZE) buf_size = NUMBER_DTOA_SIZE; diff --git a/dlls/jscript/tests/api.js b/dlls/jscript/tests/api.js index 6322eae22ce..5d457772d54 100644 --- a/dlls/jscript/tests/api.js +++ b/dlls/jscript/tests/api.js @@ -1204,6 +1204,14 @@ ok(tmp === "101.1", "num(5.5).toString(2) = " + tmp); tmp = (new Number(3)).toFixed(3); ok(tmp === "3.000", "num(3).toFixed(3) = " + tmp); +tmp = (new Number(3)).toFixed(); +ok(tmp === "3", "Number(3).toFixed() = " + tmp); +tmp = (new Number(0)).toFixed(); +ok(tmp === "0", "Number(0).toFixed() = " + tmp); +tmp = (new Number(0)).toFixed(1); +ok(tmp === "0.0", "Number(0).toFixed(1) = " + tmp); +tmp = (new Number(0)).toFixed(2); +ok(tmp === "0.00", "Number(0).toFixed(2) = " + tmp); tmp = (new Number(1.76)).toFixed(1); ok(tmp === "1.8", "num(1.76).toFixed(1) = " + tmp); tmp = (new Number(7.92)).toFixed(5); -- 2.11.4.GIT