»
EnglishFrenchVietnamese

Print - Simple Fix Length for Decimal Places - JavaScriptBank.com

Full version: jsB@nk » Calculation » Math » Simple Fix Length for Decimal Places
URL: https://www.javascriptbank.com/simple-fix-length-for-decimal-places.html

Simple Fix Length for Decimal Places © JavaScriptBank.comThis JavaScript enables you to set a fixed number of decimal places for an input number. It also provides error checking.

Full version: jsB@nk » Calculation » Math » Simple Fix Length for Decimal Places
URL: https://www.javascriptbank.com/simple-fix-length-for-decimal-places.html



JavaScript
<SCRIPT language=javascript>//<!--// SimpleFix by Wrapbitfunction format_number(dec,fix) {fixValue = parseFloat(Math.pow(10,fix));retValue = parseInt(Math.round(dec * fixValue)) / fixValue;return retValue;}function calculateIt() {form = document.form1;if(isNaN(form.dec.value) || isNaN(form.fix.value)) {alert("Input is empty or not a number");form.dec.select();return;}form.result.value = format_number(form.dec.value,form.fix.value);}//--></SCRIPT><!--    This script downloaded from www.JavaScriptBank.com    Come to view and download over 2000+ free javascript at www.JavaScriptBank.com-->


HTML
<FORM name=form1 action="" method=post>Input: <INPUT type=textbox size=10 name=dec> Fix: <INPUT type=textbox size=5 name=fix> <INPUT onclick=calculateIt() type=button value=Calculate> <BR>Output: <INPUT readOnly type=textbox name=result> </FORM><!--    This script downloaded from www.JavaScriptBank.com    Come to view and download over 2000+ free javascript at www.JavaScriptBank.com-->