Hello All,
I have updated the script to make sure below mentioned issues are fixed. Please go ahead with your testing and let me know.
var iWords = ['Zero', ' One', ' Two', ' Three', ' Four', ' Five', ' Six', ' Seven', ' Eight', ' Nine']; var ePlace = ['Ten', ' Eleven', ' Twelve', ' Thirteen', ' Fourteen', ' Fifteen', ' Sixteen', ' Seventeen', ' Eighteen', ' Nineteen']; var tensPlace = ['', ' Ten', ' Twenty', ' Thirty', ' Forty', ' Fifty', ' Sixty', ' Seventy', ' Eighty', ' Ninety']; var inWords = []; var numReversed, inWords, actnumber, i, j; function tensComplication() { 'use strict'; if (actnumber[i] === 0) { inWords[j] = ''; } else if (actnumber[i] === 1) { inWords[j] = ePlace[actnumber[i - 1]]; } else { inWords[j] = tensPlace[actnumber[i]]; } } function testSkill() { 'use strict'; var junkVal = document.getElementById('rupees').value; junkVal = Math.floor(junkVal); var obStr = junkVal.toString(); numReversed = obStr.split(''); actnumber = numReversed.reverse(); if (Number(junkVal) >= 0) { //do nothing } else { window.alert('wrong Number cannot be converted'); return false; } if (Number(junkVal) === 0) { document.getElementById('container').innerHTML = obStr + '' + 'Rupees Zero Only'; return false; } if (actnumber.length > 9) { window.alert('Oops!!!! the Number is too big to covertes'); return false; } var iWordsLength = numReversed.length; var finalWord = ''; j = 0; for (i = 0; i < iWordsLength; i++) { switch (i) { case 0: if (actnumber[i] === '0' || actnumber[i + 1] === '1') { inWords[j] = ''; } else { inWords[j] = iWords[actnumber[i]]; } inWords[j] = inWords[j] + ' Only'; break; case 1: tensComplication(); break; case 2: if (actnumber[i] === '0') { inWords[j] = ''; } else if (actnumber[i - 1] !== '0' && actnumber[i - 2] !== '0') { inWords[j] = iWords[actnumber[i]] + ' Hundred and'; } else { inWords[j] = iWords[actnumber[i]] + ' Hundred'; } break; case 3: if (actnumber[i] === '0' || actnumber[i + 1] === '1') { inWords[j] = ''; } else { inWords[j] = iWords[actnumber[i]]; } if (actnumber[i + 1] !== '0' || actnumber[i] > '0') { inWords[j] = inWords[j] + ' Thousand'; } break; case 4: tensComplication(); break; case 5: if (actnumber[i] === '0' || actnumber[i + 1] === '1') { inWords[j] = ''; } else { inWords[j] = iWords[actnumber[i]]; } if (actnumber[i + 1] !== '0' || actnumber[i] > '0') { inWords[j] = inWords[j] + ' Lakh'; } break; case 6: tensComplication(); break; case 7: if (actnumber[i] === '0' || actnumber[i + 1] === '1') { inWords[j] = ''; } else { inWords[j] = iWords[actnumber[i]]; } inWords[j] = inWords[j] + ' Crore'; break; case 8: tensComplication(); break; default: break; } j++; } inWords.reverse(); for (i = 0; i < inWords.length; i++) { finalWord += inWords[i]; } document.getElementById('container').innerHTML = obStr + ' ' + finalWord; }
Include the below code in your HTML
<input type="text" name="rupees" id="rupees" /> <input type="button" name="sr1" value="Click Here" onClick="testSkill()"/> <div id="container"></div>
If you like the script then post the comments
i used ur code but its not working so pls give me correct code for the currency convert into word with paisa
waiting for ans
thanks Sridhar Kuppalli..
your scripts works fine for me..
just i changed the quotes in entire sciprt…manually..
and its work..
how to extend this script for decimal values….
hey..gr8 job…
its working fine with few modifications…
thanks…
Thanks…
its very useful me..
Thanks a lot bro. Its work very well. A special thanks from bottom of my heart.
THANK A LOT BROTHER…BUT IT IS NOT WORKING IN INTERNET EXPLORER…
Hi,
The codes well till 99,999 but if you enter 100000 the conversion in words is “100000 One Lakh Thousand Only” whereas it should be only “one lakh only” please suggest me what should i do?
Hi Thanks a lot… Its working nicely after some corrections…. Thanks a lot…
Hi Thanks a lot… Its working nicely but we want to display fraction also please suggest some sol for that
thanks thanks a lot.. lot.. lot..
This code is very helpful.
But I face one problem in this code
when i entered 5000000 then it gives “Fifty Lakh Thousand Only”.
and this is not right according to indian format. It will be Fifty lakh only. So plz provide this type of code if you have then mail me on my email-id
gagan82991@gmail.com
Thanks in advance.
Yes, some users reported this bug in the code. Will work on this and will send you the reply.
Hai Kuppalli,
I want this function in paise format also … I got error for 5000000
Good Script. Help my mind to relax and create good concepts.
Nice one!!!
Thanks!!!
Hi Sridhar Kuppalli
Ur coding is very usefull 4 my product.
Thank U
By
Sundar.A
Hi Thanks a lot. Its working nice.
Nice One!!!!!!!!!!!
thank u for the code,
its working perfectly…..
thank u thank u very much…………
it works like a charm!
thanx a lot..it working nicely…
how to apply it in excel for converting rs to words . I install java in my pc. but I can not use this java script . pls reply me immediately
thanks a lottttttttttttttttttt
Hi All,
Updated the above script to fix some reported issues.
Please simplyfy the coding and then send to my mail …(Convert Amount in numbers to words in JavaScript)
It’s urgent sir….
Thanks you.
Please send me the simplify codeing on my mail….(Convert Amount in numbers to words in JavaScript) ….
Thanx & Regards
it save many time
Very good work. I am trying to create decimal conversion, but would appreciate someone else along with Sridhar to try it.
Nice code man
thanks………………..yar
Hi Thanks a lot. Its working nice.
how to convert float to words
thanks Sridhar Kuppalli..
thankyou somuch
thank you a lot… good script but it not working on IE.. please solve this issue….. and send on 319sunnyb@gmail.com
I will be highly thankful to you…
Thanks so much, I got it and it working nicely
Thanks…it’s Working
Thanks buddy .. its very usefull
Hi….
Awesome…It’s working fine
Thanks. its very usefull..
this script is fully helpful for me
great job, can anyone tell me how can i pass a value in php to get the output from this function
Dear expert,
accept the value from the user from keyboard using promt and convert into string.how we create this program in prompt.
You code is ok but how do i get the add in the word. eg. one thousand and six doller
Changed all Single code to double code. it worked like a charm.
can you please use this method for using forms (redirection)
I face one problem in this code
when i entered 5000000 then it gives “Fifty Lakh Thousand Only”.
and this is not right according to indian format. It will be Fifty lakh only. So plz provide this type of code if you have then mail me on my email-id
Updated the script to resolve ‘Thousand only’ error
How can I use this in Form field to convert Amount Entered in One Cell, to be converted in Words in other cell.
I Have THis
But It Only Work Till 99,999
Above that For 1,00,000 it Gives ” one hundred Thousand Only”
“”””””””””””””””PLEASE HELP””””””””””””””
DOCUMENT LEVEL JAVA SCRIPT
function ConvertToHundreds(num)
{
aTens = [ “Twenty”, “Thirty”, “Forty”, “Fifty”, “Sixty”, “Seventy”, “Eighty”, “Ninety”];
aOnes = [ “Zero”, “One”, “Two”, “Three”, “Four”, “Five”, “Six”, “Seven”, “Eight”, “Nine”,
“Ten”, “Eleven”, “Twelve”, “Thirteen”, “Fourteen”, “Fifteen”, “Sixteen”, “Seventeen”,
“Eighteen”, “Nineteen” ];
var cNum, nNum;
var cWords = “”;
num %= 1000;
if (num > 99) {
/* Hundreds. */
cNum = String(num);
nNum = Number(cNum.charAt(0));
cWords += aOnes[nNum] + ” Hundred”;
num %= 100;
if (num > 0)
cWords += ” and ”
}
if (num > 19) {
/* Tens. */
cNum = String(num);
nNum = Number(cNum.charAt(0));
cWords += aTens[nNum – 2];
num %= 10;
if (num > 0)
cWords += “-“;
}
if (num > 0) {
/* Ones and teens. */
nNum = Math.floor(num);
cWords += aOnes[nNum];
}
return cWords;
}
function ConvertToWords(num)
{
var aUnits = [ “Thousand”, “Lakh”, “Crore” ];
var cWords = (num >= 1 && num 0; i++) {
if (nLeft % 1000 > 0) {
if (i != 0)
cWords = ConvertToHundreds(nLeft) + ” ” + aUnits[i – 1] + ” ” + cWords;
else
cWords = ConvertToHundreds(nLeft) + ” ” + cWords;
}
nLeft = Math.floor(nLeft / 1000);
}
num = Math.round(num * 100) % 100;
if (num > 0)
cWords += ConvertToHundreds(num) + ” Paise”;
else
cWords += “Only”;
return cWords;
}
CALCULATION SCRIPT FOR FORM FIELD
// get the field with numbers
var f = this.getField(“Number”);
// call the convert function with the value of the number field
event.value = ConvertToWords(f.value);
I am getting a ten only when I am entering number from 11-19..pls look at it
It show Ten for values from 10 to 19