Numbers in javascript

Written by Alex Wolkov

So apparently I was in the dark,

someone (@bigel) has sent me a link to a great post about 5 missing javascript numbers functions.

In there I found a real jem!


function round(number, decimals){
return parseFloat(number.toFixed(decimals));
}

  • What’s wrong with just using (1234.56789).toFixed(2)? It’s already there on the prototype and does the same thing.

  • altryne

    nothing is wrong, expet parsefloat should be there too
    and wrapping it all in a function is readable 🙂

  • ok, what about the quickest number coercion?
    +(1234.56789).toFixed(2)