MartyrSyx Posted February 16, 2010 Share Posted February 16, 2010 Is there a rule to be able to convert a number to words? Like so: 500 becomes "Five Hundred", 125 becomes "One Hundred Twenty Five" and so forth. Link to comment Share on other sites More sharing options...
esmith Posted February 18, 2010 Share Posted February 18, 2010 Hey, anything's possible, right? /me looks around... Is there a limit to how high your numbers go? 100s? 1000s? var number = Field("Number"); // this is the only line you need to edit (see comment on line 108) function tens(tens,ones){ switch (Int(tens)){ case 9: var tensPlace = "Ninety "; break; case 8: var tensPlace = "Eighty "; break; case 7: var tensPlace = "Seventy "; break; case 6: var tensPlace = "Sixty "; break; case 5: var tensPlace = "Fifty "; break; case 4: var tensPlace = "Forty "; break; case 3: var tensPlace = "Thirty "; break; case 2: var tensPlace = "Twenty "; break; case 1: switch (Int(ones)) { case 9: var tensPlace = "Nineteen"; break; case 8: var tensPlace = "Eighteen"; break; case 7: var tensPlace = "Seventeen"; break; case 6: var tensPlace = "Sixteen"; break; case 5: var tensPlace = "Fifteen"; break; case 4: var tensPlace = "Fourteen"; break; case 3: var tensPlace = "Thirteen"; break; case 2: var tensPlace = "Twelve"; break; case 1: var tensPlace = "Eleven"; break; default: var tensPlace = "Ten"; } break; default: var tensPlace = ""; } return tensPlace; } function ones(tens,ones){ if (Int(tens) != 1){ switch (Int(ones)){ case 9: var onesPlace = "Nine "; break; case 8: var onesPlace = "Eight "; break; case 7: var onesPlace = "Seven "; break; case 6: var onesPlace = "Six "; break; case 5: var onesPlace = "Five "; break; case 4: var onesPlace = "Four "; break; case 3: var onesPlace = "Three "; break; case 2: var onesPlace = "Two "; break; case 1: var onesPlace = "One "; break; default: var onesPlace = ""; } } else var onesPlace = ""; return onesPlace; } var digits = number.split(""); var places = digits.length; // add "case 5:" for 10,000s, "case 6:" for 100,000s, etc. switch (places) { case 4: var numberText = ones(0,digits[0]) + "Thousand " + ones(0,digits[1]); if (ones(0,digits[1]) != "") numberText += "Hundred "; numberText += tens(digits[2],digits[3]) + ones(digits[2],digits[3]); break; case 3: var numberText = ones(0,digits[0]) + "Hundred " + tens(digits[1],digits[2]) + ones(digits[1],digits[2]); break; case 2: var numberText = tens(digits[0],digits[1]) + ones(digits[0],digits[1]); break; default: var numberText = ones(0,digits[0]); } return numberText; Link to comment Share on other sites More sharing options...
Dan Korn Posted February 18, 2010 Share Posted February 18, 2010 Try any of the first few hits from this: http://www.google.com/search?q=javascript+number+to+words Link to comment Share on other sites More sharing options...
MartyrSyx Posted February 19, 2010 Author Share Posted February 19, 2010 Thanks Guys. I feel like an idiot. I searched different javascript language references online. I didn't even think about looking for and actual script. Looks like this will work. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.