var demo = 5; alert (demo.toFixed(4)); toFixed( number ), format the number as a string with number decimal places. Note that the original value must be a numerical value, such as var demo = 1; demo = demo.toFixed(4); and var demo='1'; demo = demo.toFixed(4); will not work.