JavaScript Numbers


toFixed() will select exact amount of decimals to display.

parseFloat() turns strings with decimals into numbers.

Use both in combination to get exact values in math operations.

parseInt() takes first available integer at the front of string.

Use a radix value to ensure correct parsing. parseInt("021", 10);. This will ensure base 10 parsing.

To test for a number, use typeof AND isNAN()

function isThisActuallyANumberDontLie(data){
  return (typeof data === "number" && !isNaN(data) );


Code School JavaScript Best Practices