Format currency using javascript /JQuery
Posted by Raj
Format currency using javascript /JQuery
In this article,I will explain how to Format currency using javascript.it is very easy to format currency in javascript.I have written simple function to format currency in JavaScript.
Example:
<html>
<head>
<title>Format currency (comma seperated) using javascript</title>
<script language="javascript" type="text/javascript">
function FormattedCurrency(currency)
{
var split_num = currency.split('.',2)//Seperate Integer Number and decimal number.
if(isNaN(parseInt(split_num[0])))
{
return 'Please Enter Amount';
}
else
if(parseInt(split_num[0]) < 0)
{
var minus_nummber = '-';
}
else
var minus_nummber = '';
integer = Math.abs(parseInt(split_num[0]));
var number = new String(integer);
var num = [];
while(number.length > 3)
{
var number1 = number.substr(number.length-3);
num.unshift(number1);
number = number.substr(0,number.length-3);
}
if(number.length > 0) { num.unshift(number); }
number = num.join(',');
if(parseInt(split_num[1]).length < 1)
{
currency = number;
}
else
{
currency = number + '.' + parseInt(split_num[1]); }
final_amount = minus_nummber + currency;
alert(final_amount);
}
var currency="1300.40";
var currency=FormattedCurrency(currency);
</script>
</head>
</html>
In this article,I will explain how to Format currency using javascript.it is very easy to format currency in javascript.I have written simple function to format currency in JavaScript.
Example:
<html>
<head>
<title>Format currency (comma seperated) using javascript</title>
<script language="javascript" type="text/javascript">
function FormattedCurrency(currency)
{
var split_num = currency.split('.',2)//Seperate Integer Number and decimal number.
if(isNaN(parseInt(split_num[0])))
{
return 'Please Enter Amount';
}
else
if(parseInt(split_num[0]) < 0)
{
var minus_nummber = '-';
}
else
var minus_nummber = '';
integer = Math.abs(parseInt(split_num[0]));
var number = new String(integer);
var num = [];
while(number.length > 3)
{
var number1 = number.substr(number.length-3);
num.unshift(number1);
number = number.substr(0,number.length-3);
}
if(number.length > 0) { num.unshift(number); }
number = num.join(',');
if(parseInt(split_num[1]).length < 1)
{
currency = number;
}
else
{
currency = number + '.' + parseInt(split_num[1]); }
final_amount = minus_nummber + currency;
alert(final_amount);
}
var currency="1300.40";
var currency=FormattedCurrency(currency);
</script>
</head>
</html>
This entry was posted on October 4, 2009 at 12:14 pm, and is filed under
format currency,
javascript format money,
javascript format numbers,
javascript formatcurrency,
javascript number to currency,
JAVSCRIPT,
money exchange script,
the money exchange
.You can leave a response, or trackback from your own site.