I have a bit of javascript that dynamically multiplies what users are typing in a text field (by the base var), and displays it in a span. Now I'm just trying to figure out how to get the decimal places of the result to float to 2 places, i.e. 10.00 instead of 10 I found the toFixed function, but can't seem to use it properly... I'd appreciate any help. Thanks
<input id="quantity">
<span id="result"></span>
<script>
window.onload = function() {
var base = 3;
document.getElementById('quantity').onkeyup = function() {
if(this.value.length == 0) {
document.getElementById('result').innerHTML = '';
return;
}
var number = parseInt(this.value);
if(isNaN(number)) return;
document.getElementById('result').innerHTML = number * base;
};
document.getElementById('quantity').onkeyup();
};
parseInthere? It will turn '4.21' into '4'. So the user will be told that 4.21 * 3 = 12.00, which it doesn't.parseFloatwill yield a floating point value.