Number to Text

19 views
Skip to first unread message

Jason Campbell

unread,
Oct 23, 2015, 12:57:01 PM10/23/15
to ParaSQL Support
I have a currency field that I would like to reference to populate a text field with the written version. For recording and printing checks.

Any ideas?
Thanks

ParaSQL Support

unread,
Nov 5, 2015, 1:46:04 PM11/5/15
to ParaSQL Support
Using an @value(MyTable.MyNumbeField) reference will return a number. 
You can simply convert it to text using toString(). 

So it would look something like this:

@value(MyTable.MyNumbeField).toString()

Jason Campbell

unread,
Nov 5, 2015, 2:25:52 PM11/5/15
to ParaSQL Support
To clarify, if the check is for $500.00 the function I need would reference that value and write "Five Hundred Dollars and Zero Cents" as a calculated value.

ParaSQL Support

unread,
Nov 6, 2015, 1:25:31 PM11/6/15
to ParaSQL Support
Below is a function you can use to print numbers in words as they might appear on a check.
You may need to tweak it a bit to fit your particular needs.

function convertCurrencyToWords(num) {

   
var a = ['','one ','two ','three ','four ', 'five ','six ','seven ','eight ','nine ','ten ',   'eleven ','twelve ','thirteen ','fourteen ','fifteen ','sixteen ','seventeen ','eighteen ','nineteen '];
   
var b = ['', '', 'twenty','thirty','forty','fifty', 'sixty','seventy','eighty','ninety'];

   
if (num >= 100000) return 'ERROR: number too large to print';

   
var dollars = Math.floor(num);
   
var cents = Math.round((num - dollars) * 100);

   
var n = ('000000000' + dollars).substr(-9).match(/^(\d{2})(\d{2})(\d{2})(\d{1})(\d{2})$/);
   
if (!n) return 'ERROR: bad number';

   
var str = '';
    str
+= (n[3] != 0) ? (a[Number(n[3])] || b[n[3][0]] + ' ' + a[n[3][1]]) + 'thousand ' : '';
    str
+= (n[4] != 0) ? (a[Number(n[4])] || b[n[4][0]] + ' ' + a[n[4][1]]) + 'hundred ' : '';
    str
+= (n[5] != 0) ? ((str != '') ? '' : '') + (a[Number(n[5])] || b[n[5][0]] + ' ' + a[n[5][1]]) : '' ;
    str
+= dollars > 0 ? '' : 'zero ';
    str
+= cents > 0 ? 'and '+(cents<10?'0'+cents:cents)+'/100 ' : (dollars > 0 ? 'only ' : '');

   
return str;
}

convertCurrencyToWords
( @value(Orders.Order_Total) );


Jason Campbell

unread,
Nov 6, 2015, 1:47:23 PM11/6/15
to ParaSQL Support
Wow, works like a charm as is.

Thank you
Reply all
Reply to author
Forward
0 new messages