JavaScript to print Amount (In Words)

By | November 5, 2015

As you know, we have been writing blogs exploring the various features implemented in Sage CRM. With the help of JavaScript codes or say Client side API, customization efforts of the programmer’s life has come to an ease. We have already posted few blogs about writing JavaScript codes in .js files and calling the same in Custom Content of any screen.

Recently we came across a requirement, where we had to display an Amount summed up (In figures) into words. Thought of sharing this post, as it would help many of the Billing departments to print Billing Invoices from CRM.

New Stuff: Chat Rooms within Sage CRM

To achieve this functionality you can refer below written script. Simply, create a new js file and call the same on the field where you need the display the output.

<Snippet>
//declaring arrays and assigning values to them.
var th = [”,’thousand’, ‘million’, ‘billion’, ‘trillion’];
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 for converting numbers to words
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[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,’ ‘);
}
</Snippet

On calling the script from the Custom Content section of CRM, output will be displayed as shown below.
1

31 thoughts on “JavaScript to print Amount (In Words)

  1. Pingback: house for sale hua hin

  2. Pingback: genie168

  3. Pingback: เว็บตรงสล็อต

  4. Pingback: บาคาร่าเกาหลี

  5. Pingback: how to open mkx cart

  6. Pingback: สล็อตเว็บตรง สมัครใหม่ เล่นเกมไหนโบนัสก็แตก

  7. Pingback: ปั่นสล็อตเว็บไหน วางเดิมพันปุ๊บ ได้เงินรางวัลปั๊บ

  8. Pingback: chat rooms

  9. Pingback: ปั่นสล็อต upx1688 โบนัสแตกบ่อย

  10. Pingback: เกมยิงปลา Fishing GOD

  11. Pingback: my profile

  12. Pingback: pg slot

  13. Pingback: ดูบอลสด66

  14. Pingback: drain cleaning phoenix

  15. Pingback: Buy marijuana online

  16. Pingback: wings789

  17. Pingback: กระดาษสติ๊กเกอร์ความร้อน

  18. Pingback: เติมเกม

  19. Pingback: King Chance

  20. Pingback: site

  21. Pingback: DeepBLOK ระบบสมาชิก

  22. Pingback: pin up casino descargar

  23. Pingback: ผู้ผลิต โบลเวอร์

  24. Pingback: แทงหวย

  25. Pingback: Cbd vape pen uk

  26. Pingback: เด็กเอ็น

  27. Pingback: พลาสติกปูพื้นก่อนเทคอนกรีต

  28. Pingback: โฆษณายา

  29. Pingback: Nolimit City ค่ายสล็อตยุโรป

  30. Pingback: ส่งsms

  31. Pingback: Pregonagropecuario marketplace for top agri deals

Comments are closed.