By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,967 Members | 1,625 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,967 IT Pros & Developers. It's quick & easy.

how to convert the numbers into words

P: 1
how to convert the numbers into words in asp.net using c#,please help me,its very urgent....?
Nov 26 '07 #1
Share this Question
Share on Google+
2 Replies


P: 65
USE JS :

<HTML>
<HEAD>
<script type="text/javascript" >

// American Numbering System
var th = ['','thousand','million', 'billion','trillion'];
// uncomment this line for English Number System
// var th = ['','thousand','million', 'milliard','billion'];

var dg = ['zero','one','two','three','four', 'five','six','seven','eight','nine']; var tn = ['ten','eleven','twelve','thirteen', 'fourteen','fifteen','sixteen', 'seventeen','eighteen','nineteen']; var tw = ['twenty','thirty','forty','fifty', 'sixty','seventy','eighty','ninety'];
function toWords(s)
{s = s.replace(/[\, ]/g,''); if (s != String(parseFloat(s))) return 'not a number'; var x = s.indexOf('.'); if (x == -1) x = s.length; if (x > 15) return 'too big'; var n = s.split(''); var str = ''; var sk = 0; for (var i=0; i < x; i++) {if ((x-i)%3==2) {if (n[i] == '1') {str += tn[Number(n[i+1])] + ' '; i++; sk=1;} else if (n[i]!=0) {str += tw[n[i]-2] + ' ';sk=1;}} else if (n[i]!=0) {str += dg[n[i]] +' '; if ((x-i)%3==0) str += 'hundred ';sk=1;} if ((x-i)%3==1) {if (sk) str += th[(x-i-1)/3] + ' ';sk=0;}} if (x != s.length) {var y = s.length; str += 'point '; for (var i=x+1; i<y; i++) str += dg[n[i]] +' ';} return str.replace(/\s+/g,' ');}

</script>
</HEAD>
<BODY>
<form name="test"><input type="text" name="inum" value="" size="18"><br><br>
<input type="button" value="To Words" onclick="test.rnum.value = toWords(test.inum.value);">

<br><br><textarea name="rnum" cols="40" rows="5"></textarea>
<P>&nbsp;</P>

</BODY>
</HTML>
Nov 27 '07 #2

jhardman
Expert 2.5K+
P: 3,405
how to convert the numbers into words in asp.net using c#,please help me,its very urgent....?
moved to .NET forum

numberrs in what format to words in what format?

Jared
Nov 28 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.