Convert Number to Indian Currency – Javascript

The below code to convert the number to Indian Currency.

<script language=”javascript” type=”text/javascript”>
function getFormattedNumber(A){
return(“”+A).charAt(0)!=”-“?getFormattedPositiveNumber(A):”-“+getFormattedPositiveNumber(-A)
}
function getRoundedAmount(E) {
var A = 2;
var D = E * Math.pow(10, A);
var C = Math.round(D);
var B = C / Math.pow(10, A);
return B.toString()
}
function getFormattedPositiveNumber(A, G) {
A = “” + A;
A = A.replace(/,/g, “”);
A = getRoundedAmount(A);
number = A;
if (number.length > 3 && number.length <= 12) {
var C = number.substring(number.length – 3, number.length);
var B = number.substring(0, number.length – 3);
var E = makeComma(B);
E = E + “,” + C;
if (G == 1) {
if (E.length > 11) {
var F = E.substr(0, 11);
var D = E.substr(F.length, E.length);
returnString = F + “<br>” + D;
return returnString
} else {
return E
}
} else {
return E
}
} else if (number.length > 12) {
alert(‘Number exceeds 12digits…’);
}
return number
}
function makeComma(A) {
if (A.length <= 2) {
return A
}
length1 = A.substr(0, (A.length – 2));
formattedInput = makeComma(length1) + “,” + A.substring(A.length – 2, A.length);
return formattedInput
}
function changeNumber(obj, val) {
val = getFormattedNumber(val);
obj.value = val;
}
var n = 12345223;
alert(getFormattedNumber(n));

</script>
<input type=”text” id=”” name=”txt_number” value=”” onkeyup=”javascript:changeNumber(this,this.value);” />

About selvam4win

I am Selvam. I am very jolly person and frank one.

Posted on April 23, 2012, in javascript and tagged , , . Bookmark the permalink. Leave a comment.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: