# Numbers to string

Does anyone have an idea to use a free api for numbers to string with no limits or a javascript that works ?

What are you trying to do? A template column can convert a number to a string. You could use javascript too, but I guess it would be better to understand what you are attempting.

number.toString()

How to achive that?

Am generating a document where it has to mention the Number of cheque amount

Ok. I thought you meant just converting a number to a string. â€ś1000.00â€ť converted from numeric to a string still is â€ś1000.00â€ť. But as I understand it, you actually want it to say â€śOne Thousandâ€ť or something like that?

I did a quick google search and found something. Try this in a javascript column and point your P1 parameter to the column that contains the number.

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

var dg_val = ['zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine'];
var tn_val = ['ten', 'eleven', 'twelve', 'thirteen', 'fourteen', 'fifteen', 'sixteen', 'seventeen', 'eighteen', 'nineteen'];
var tw_val = ['twenty', 'thirty', 'forty', 'fifty', 'sixty', 'seventy', 'eighty', 'ninety'];
function toWords(s) {
s = s.toString();
s = s.replace(/[\, ]/g, '');
if (s != parseFloat(s))
return 'not a number ';
var x_val = s.indexOf('.');
if (x_val == -1)
x_val = s.length;
if (x_val > 15)
return 'too big';
var n_val = s.split('');
var str_val = '';
var sk_val = 0;
for (var i = 0; i < x_val; i++) {
if ((x_val - i) % 3 == 2) {
if (n_val[i] == '1') {
str_val += tn_val[Number(n_val[i + 1])] + ' ';
i++;
sk_val = 1;
} else if (n_val[i] != 0) {
str_val += tw_val[n_val[i] - 2] + ' ';
sk_val = 1;
}
} else if (n_val[i] != 0) {
str_val += dg_val[n_val[i]] + ' ';
if ((x_val - i) % 3 == 0)
str_val += 'hundred ';
sk_val = 1;
}
if ((x_val - i) % 3 == 1) {
if (sk_val)
str_val += th_val[(x_val - i - 1) / 3] + ' ';
sk_val = 0;
}
}
if (x_val != s.length) {
var y_val = s.length;
str_val += 'point ';
for (var i = x_val + 1; i < y_val; i++)
str_val += dg_val[n_val[i]] + ' ';
}
return str_val.replace(/\s+/g, ' ');
}

``````
3 Likes

Thanks Jeff

Wannted to know if this is normal

A lot of times, those errors seem to usually be a step behind and actually show a previous error.

But in this case it also could be failing if an empty (null) parameter is being passed in. In that case, add this to the beginning of the toWords function. That way it will bounce out, and return a blank, before encountering any error due to a null parameter.

``````if (s == null) {
return '';
}
``````
2 Likes

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.