Home
Analytics
convert Number into word
santoshsingh1056
Hi all,
Is there any function in BIRT that convert a number into word.
This is something like if i am gating 10,563 then it give us ONE THOUSAND FIVE HUNDRED AND SIXTY THREE.
I AM USING Version: 3.4.1.
REGARDS
SANTOSH.
Find more posts tagged with
Comments
mwilliams
There currently is not a BIRT function to do this. You can probably find a function that does this on the web somewhere and use it within BIRT. This would also be a good enhancement request for BIRT to have this functionality. You can submit a request at
http://www.birt-exchange.org/org/resources/bug-reporting/
.
santoshsingh1056
Hi BIRT Guru
Meany thanks for response.
I am taking help of javascript for this issue.I am very close to solve this.Once get solved i will share that on this post.
I still have one more open discussion regarding merging reports with proper paging order.
I am not able to find any solution for that.
If you can see please provide me solution for that.
Regards,
Santosh
mwilliams
If you create a javascript function to do this, it would be a good addition to the <a class='bbc_url' href='
http://www.birt-exchange.org/org/devshare/'>devShare</a>
;
santoshsingh1056
<blockquote class='ipsBlockquote' data-author="'mwilliams'" data-cid="76884" data-time="1305129426" data-date="11 May 2011 - 08:57 AM"><p>
If you create a javascript function to do this, it would be a good addition to the <a class='bbc_url' href='
http://www.birt-exchange.org/org/devshare/'>devShare</a><br
/></p></blockquote>
<br />
<br />
Here is the required javascript to do this...<br />
<br />
var th = ['','thousand','million', 'billion','trillion'];<br />
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.toString(); s = s.replace(/[\, ]/g,''); if (s != 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
== '1') {str += tn[Number(n[i+1])] + ' '; i++; sk=1;} else if (n
!=0) {str += tw[n
-2] + ' ';sk=1;}} else if (n
!=0) {str += dg[n
] +' '; 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
] +' ';} return str.replace(/\s+/g,' ');}<br />
<br />
<br />
just pass your data column as argument.<br />
<br />
<br />
Regards,<br />
Santosh....
johnw
Michael,
Would it be helpful if I created a Function extension to do this and add it to the Marketplace? This is not the first time this request has come up, and I've had it on my ToDo list for a while to write a post about it. wondering if it wouldn't just be better to do an extension.
John
santoshsingh1056
<blockquote class='ipsBlockquote' data-author="'johnw'" data-cid="76968" data-time="1305238515" data-date="12 May 2011 - 03:15 PM"><p>
Michael,<br />
<br />
Would it be helpful if I created a Function extension to do this and add it to the Marketplace? This is not the first time this request has come up, and I've had it on my ToDo list for a while to write a post about it. wondering if it wouldn't just be better to do an extension.<br />
<br />
John<br /></p></blockquote>
<br />
Hi Michael,<br />
<br />
Please let me Know if there is any error that might be possible with this script.<br />
To use this script pass your Decimal dataSet to this function [toWords(s)].<br />
<br />
Regards<br />
<br />
Santosh..
mwilliams
John -Yeah. I think this would be a good extension to add. I've seen it pass through several times as well. If you add it, post the link to the marketplace app in here!
Santosh - From the limited testing I did with it, it seems to work correctly to me! Nice work!
gangadhar15
<p>Santhosh,</p>
<p> </p>
<p> Please can you attach with sample, I am trying to do but unable to achieve the result.</p>
<p> </p>
<p>Thanks</p>
<p>M. Gangadhar</p>
Clement Wong
<p>All you would need to do is put the code from Santosh's post (<a data-ipb='nomediaparse' href='
http://developer.actuate.com/community/forum/index.php?/topic/22298-convert-number-into-word/?p=76920'>http://developer.actuate.com/community/forum/index.php?/topic/22298-convert-number-into-word/?p=76920</a>)
in a .JS file. You'll be able to use other number to words JavaScript functions if this particular one doesn't meet your requirements.</p>
<p> </p>
<p>Then, in your .rptdesign, add that .JS file as a resource under the report's <em>General > Properties Editor - Report > Resources > Javascript Files > Add Files...</em></p>
<p> </p>
<p>Next, just reference that function and pass it a number. In the attached example (created in OS BIRT 3.7.2), I'm using the <strong>toWords </strong>function in the Computed Column of the Data Set.</p>
<p> </p>
<p><em>*** Rename the "toWords.js.txt" to "toWords.js", by removing the .txt extension because .JS extension files are rejected as attachments.</em></p>