jscript: Fixed Number.toFixed for value 0 with 0 precision.

This commit is contained in:
Jacek Caban 2012-12-17 13:35:54 +01:00 committed by Alexandre Julliard
parent 59e339faac
commit 9de9c353ac
2 changed files with 12 additions and 2 deletions

View File

@ -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;

View File

@ -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);