Script Categories

Forms >>> Currency Format.

This script accepts a number or string and formats it like U.S. currency. Adds the dollar sign, rounds to two places past the decimal, adds place holding zeros, and commas where appropriate. Occurs when the user clicks the button or when they finish entering the money amount (and click into the next field).

Enter a number then click the button:

or enter a number and click another field:

Add the below code to the <body> section of your page:

<script language="javascript" type="text/javascript">
/* Visit for full source code
and get more free JavaScript, CSS and DHTML scripts! */
<!-- Begin
function formatCurrency(num) {
num = num.toString().replace(/\$|\,/g,'');
num = "0";
sign = (num == (num = Math.abs(num)));
num = Math.floor(num*100+0.50000000001);
cents = num%100;
num = Math.floor(num/100).toString();
cents = "0" + cents;
for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
num = num.substring(0,num.length-(4*i+3))+','+
return (((sign)?'':'-') + '$' + num + '.' + cents);
//  End -->
<form name=currencyform>
Enter a number then click the button: <input type=text name=input size=10 value="1000434.23">
type=button value="Convert" onclick="this.form.input.value=formatCurrency(this.form.input.value);">
or enter a number and click another field: <input type=text name=input2 size=10 value="1000434.23" onBlur="this.value=formatCurrency(this.value);">

JavaScript Editor Get Advanced
JavaScript and Ajax Editor,
Validator and Debugger!

1st JavaScript Editor.

Code was highlighted by 1st JavaScript Editor (The Best JavaScript Editor!).

online casino