codice:
<!doctype html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Esempio</title>
<script type="text/javascript">
function formatNumber(sFloatNum) {
	var aFragms = parseFloat(sFloatNum.replace(',','.')).toFixed(2).split(".");
	return aFragms[0].replace(/(\d{3})+$/g, ".$&").replace(/^\./, "").replace(/\d{3}(?!$)/g, "$&.") + "," + aFragms[1];
}
</script>
</head>

<body>
<form name="myForm">


non formattato: <input type="text" name="originale" value="5000" />

formattato: <input type="text" name="formattato" value="" />

<input type="button" value="formatta" onclick="this.form.formattato.value=formatNumber(this.form.originale.value);" /></p>
</form>
</body>
</html>