|
-
Jun 20th, 2003, 07:47 AM
#1
Thread Starter
New Member
How to convert figures into words in vb /asp?
Please let me know how to convert figures into words. Eg: 250.00 into "Two hundred fifty only."
-
Jun 20th, 2003, 08:25 AM
#2
Fanatic Member
<html>
<head>
<script language="JavaScript"><!--
function makeArray0() {
for (i = 0; i<makeArray0.arguments.length; i++)
this[i] = makeArray0.arguments[i];
}
var numbers = new makeArray0('','one','two','three','four','five','six','seven','eight','nine','ten','eleven','twelve' ,'thirteen','fourteen','fifthteen','sixteen','seventeen','eighteen','nineteen');
var numbers10 = new makeArray0('','ten','twenty','thirty','fourty','fifty','sixty','seventy','eighty','ninety');
function chequeAmount(input) {
var dollars = Math.floor(input);
var cents = Math.round((input*100 - dollars*100));
var thousands = (dollars - dollars % 1000) / 1000;
dollars -= thousands * 1000;
var hundreds = (dollars - dollars % 100) / 100;
dollars -= hundreds * 100;
var output = '';
output += (thousands > 0 ? fN(thousands) + ' thousand ' : '') +
(hundreds > 0 ? fN(hundreds) + ' hundred ' : '') +
(dollars > 0 ? fN(dollars) + ' ' : '') +
((thousands > 0 || hundreds > 0 || dollars > 0) ? 'dollars ' : '') +
((Math.floor(input) > 0 && cents > 0) ? 'and ' : '') +
(cents > 0 ? fN(cents) + ' cents' : '');
return output.substring(0,1).toUpperCase() + output.substring(1);
}
function fN(i) {
if (i<20) return numbers[i];
var tens = (i - i % 10) / 10, units = i - (i - i % 10);
return numbers10[tens] + ((tens > 0 && units > 0) ? '-' : '') + numbers[units];
}
//--></script>
</head>
<body>
<form>
<input type="text" name="amount">
<input type="text" name="answer" size="80">
<input type="button" value="Convert" onClick="this.form.answer.value=chequeAmount(this.form.amount.value - 0)">
</form>
</body>
</html>
Last edited by davebat; Jun 20th, 2003 at 08:33 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|