Once you read what What Every Computer Scientist Should Know About Floating-Point Arithmetic you could use the .toFixed()
function:
var result = parseFloat('2.3') + parseFloat('2.4');
alert(result.toFixed(2));
More Related Contents:
- Read/Write bytes of float in JS
- Adding to Number.MAX_VALUE
- In JavaScript, why does zero divided by zero return NaN, but any other divided by zero return Infinity?
- Why does adding two decimals in Javascript produce a wrong result? [duplicate]
- JavaScript: Round to a number of decimal places, but strip extra zeros
- Get the percentage of a number with javascript [closed]
- What is the quickest way to subtract a variable from a number and set the variable?
- Slope function error(sort-of)… again [closed]
- JavaScript % (modulo) gives a negative result for negative numbers
- JavaScript math, round to two decimal places [duplicate]
- How to deal with floating point number precision in JavaScript?
- Javascript: formatting a rounded number to N decimals
- How to perform an integer division, and separately get the remainder, in JavaScript?
- Safe evaluation of arithmetic expressions in Javascript
- How can I remove the decimal part from JavaScript number?
- What is the fastest factorial function in JavaScript? [closed]
- What’s the algorithm to calculate aspect ratio?
- Why does modulus operator return fractional number in javascript?
- How can I specify the base for Math.log() in JavaScript?
- Avoiding problems with JavaScript’s weird decimal calculations
- Calculating the shortest route between two points
- understanding floating point variables
- How to round up to the nearest 100 in JavaScript
- JS how to find the greatest common divisor [closed]
- How to find the least common multiple of a range of numbers?
- How to simplify a decimal into the smallest possible fraction?
- Show a leading zero if a number is less than 10 [duplicate]
- parseFloat rounding
- Integers in JavaScript
- Javascript: PI (π) Calculator