As per specification, -0 is the only number which Number(String(x))
do not generate the original value of x
.
Sadly, all stander toString
method tell -0
just like 0
. Which convert to string '0'
instead of '-0'
.
You may be interested in function uneval
on Firefox. But since its Firefox only, non-standard feature. You should avoid using it on website. (Also, never do eval(uneval(x))
as deep clone please)
Maybe you have to do this with your own codes:
function numberToString(x) {
if (1 / x === -Infinity && x === 0) return '-0';
return '' + x;
}