{"id":11387,"date":"2015-11-05T07:14:23","date_gmt":"2015-11-05T07:14:23","guid":{"rendered":"http:\/\/www.greytrix.com\/blogs\/sagecrm\/?p=11387"},"modified":"2022-11-04T10:14:19","modified_gmt":"2022-11-04T10:14:19","slug":"javascript-to-print-amount-in-words","status":"publish","type":"post","link":"https:\/\/www.greytrix.com\/blogs\/sagecrm\/2015\/11\/05\/javascript-to-print-amount-in-words\/","title":{"rendered":"JavaScript to print Amount (In Words)"},"content":{"rendered":"<p style=\"text-align: justify;\">As you know, we have been writing blogs exploring the various features implemented in <a href=\"http:\/\/www.sagesoftware.co.in\/product-sage-crm\" target=\"_blank\" rel=\"noopener\">Sage CRM<\/a>. With the help of JavaScript codes or say Client side API, customization efforts of the programmer\u2019s life has come to an ease. We have already posted few blogs about writing JavaScript codes in\u00a0<strong>.js <\/strong>files and calling the same in Custom Content of any screen.<\/p>\n<p style=\"text-align: justify;\">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.<\/p>\n<p style=\"text-align: justify;\"><span style=\"color: #993300;\"><strong><em>New Stuff:<\/em><span style=\"color: #000000;\"><em>\u00a0<\/em><\/span><\/strong><span style=\"color: #000000;\"><a href=\"https:\/\/www.greytrix.com\/blogs\/sagecrm\/2015\/11\/04\/chat-rooms-within-sage-crm\/\" target=\"_blank\" rel=\"noopener\">Chat Rooms within Sage CRM<\/a><\/span><\/span><\/p>\n<p style=\"text-align: justify;\">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.<\/p>\n<p style=\"text-align: justify;\"><strong><em>&lt;Snippet&gt;<\/em><\/strong><br \/>\n\/\/declaring arrays and assigning values to them.<br \/>\nvar th = [&#8221;,&#8217;thousand\u2019, \u2018million&#8217;, &#8216;billion\u2019, \u2018trillion&#8217;];<br \/>\nvar dg = [&#8216;zero&#8217;,&#8217;one&#8217;,&#8217;two&#8217;,&#8217;three&#8217;,&#8217;four&#8217;, &#8216;five&#8217;,&#8217;six&#8217;,&#8217;seven&#8217;,&#8217;eight&#8217;,&#8217;nine&#8217;];<br \/>\nvar tn=[&#8216;ten&#8217;,&#8217;eleven&#8217;,&#8217;twelve&#8217;,&#8217;thirteen&#8217;,&#8217;fourteen&#8217;,&#8217;fifteen&#8217;,&#8217;sixteen&#8217;,&#8217;seventeen&#8217;,&#8217;eighteen&#8217;,&#8217;nineteen&#8217;];<br \/>\nvar tw = [&#8216;twenty&#8217;,&#8217;thirty&#8217;,&#8217;forty&#8217;,&#8217;fifty&#8217;, &#8216;sixty&#8217;,&#8217;seventy&#8217;,&#8217;eighty&#8217;,&#8217;ninety&#8217;];<br \/>\n\/\/function for converting numbers to words<br \/>\nFunction toWords(s)<br \/>\n{<br \/>\ns = s.toString();<br \/>\ns = s.replace(\/[\\, ]\/g,&#8221;);<br \/>\nif (s != parseFloat(s)) return &#8216;not a number&#8217;;<br \/>\nvar x = s.indexOf(&#8216;.&#8217;);<br \/>\nif (x == -1)<br \/>\nx = s.length;<br \/>\nif (x &gt; 15)<br \/>\nreturn &#8216;too big&#8217;;<br \/>\nvar n = s.split(&#8221;);<br \/>\nvar str = &#8221;;<br \/>\nvar sk = 0;<br \/>\nfor (var i=0; i &lt; x; i++)<br \/>\n{<br \/>\nif ((x-i)%3==2)<br \/>\n{<br \/>\nif (n[i] == &#8216;1&#8217;)<br \/>\n{<br \/>\nstr += tn[Number(n[i+1])] + &#8216; &#8216;;<br \/>\ni++;<br \/>\nsk=1;<br \/>\n}<br \/>\nelse if (n[i]!=0)<br \/>\n{<br \/>\nstr += tw[n[i]-2] + &#8216; &#8216;;<br \/>\nsk=1;<br \/>\n}<br \/>\n}<br \/>\nelse if (n[i]!=0)<br \/>\n{<br \/>\nstr += dg[n[i]] +&#8217; &#8216;;<br \/>\nif ((x-i)%3==0) str += &#8216;hundred &#8216;;<br \/>\nsk=1;<br \/>\n}<br \/>\nif ((x-i)%3==1)<br \/>\n{<br \/>\nif (sk)<br \/>\nstr += th[(x-i-1)\/3] + &#8216; &#8216;;<br \/>\nsk=0;<br \/>\n}<br \/>\n}<br \/>\nif (x != s.length)<br \/>\n{<br \/>\nvar y = s.length;<br \/>\nstr += &#8216;point &#8216;;<br \/>\nfor (var i=x+1; i&lt;y; i++)<br \/>\nstr += dg[n[i]] +&#8217; &#8216;;<br \/>\n}<br \/>\nreturn str.replace(\/\\s+\/g,&#8217; &#8216;);<br \/>\n}<br \/>\n<strong><em>&lt;\/Snippet<\/em><\/strong><\/p>\n<p>On calling the script from the Custom Content section of CRM, output will be displayed as shown below.<br \/>\n<a href=\"https:\/\/www.greytrix.com\/blogs\/sagecrm\/wp-content\/uploads\/2015\/11\/1.jpg\"><img fetchpriority=\"high\" decoding=\"async\" class=\"aligncenter size-full wp-image-11388\" src=\"https:\/\/www.greytrix.com\/blogs\/sagecrm\/wp-content\/uploads\/2015\/11\/1.jpg\" alt=\"1\" width=\"379\" height=\"238\" \/><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>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\u2019s life has come to an ease. We have already posted few blogs about writing JavaScript codes in\u00a0.js files and calling the same in\u2026 <span class=\"read-more\"><a href=\"https:\/\/www.greytrix.com\/blogs\/sagecrm\/2015\/11\/05\/javascript-to-print-amount-in-words\/\">Read More &raquo;<\/a><\/span><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[152,200,1],"tags":[553,613,614,685,1471,1686],"class_list":["post-11387","post","type-post","status-publish","format-standard","hentry","category-feature","category-javascript-sage-crm","category-uncategorized","tag-amount-in-words","tag-billing","tag-billing-invoices","tag-client-side-api","tag-javascript","tag-numbers-in-words"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>JavaScript to print Amount (In Words) - Sage CRM \u2013 Tips, Tricks and Components<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.greytrix.com\/blogs\/sagecrm\/2015\/11\/05\/javascript-to-print-amount-in-words\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"JavaScript to print Amount (In Words) - Sage CRM \u2013 Tips, Tricks and Components\" \/>\n<meta property=\"og:description\" content=\"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\u2019s life has come to an ease. We have already posted few blogs about writing JavaScript codes in\u00a0.js files and calling the same in\u2026 Read More &raquo;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.greytrix.com\/blogs\/sagecrm\/2015\/11\/05\/javascript-to-print-amount-in-words\/\" \/>\n<meta property=\"og:site_name\" content=\"Sage CRM \u2013 Tips, Tricks and Components\" \/>\n<meta property=\"article:published_time\" content=\"2015-11-05T07:14:23+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-11-04T10:14:19+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/www.greytrix.com\/blogs\/sagecrm\/wp-content\/uploads\/2015\/11\/1.jpg\" \/>\n<meta name=\"author\" content=\"greysagecrm\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"greysagecrm\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.greytrix.com\/blogs\/sagecrm\/2015\/11\/05\/javascript-to-print-amount-in-words\/\",\"url\":\"https:\/\/www.greytrix.com\/blogs\/sagecrm\/2015\/11\/05\/javascript-to-print-amount-in-words\/\",\"name\":\"JavaScript to print Amount (In Words) - Sage CRM \u2013 Tips, Tricks and Components\",\"isPartOf\":{\"@id\":\"https:\/\/www.greytrix.com\/blogs\/sagecrm\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.greytrix.com\/blogs\/sagecrm\/2015\/11\/05\/javascript-to-print-amount-in-words\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.greytrix.com\/blogs\/sagecrm\/2015\/11\/05\/javascript-to-print-amount-in-words\/#primaryimage\"},\"thumbnailUrl\":\"http:\/\/www.greytrix.com\/blogs\/sagecrm\/wp-content\/uploads\/2015\/11\/1.jpg\",\"datePublished\":\"2015-11-05T07:14:23+00:00\",\"dateModified\":\"2022-11-04T10:14:19+00:00\",\"author\":{\"@id\":\"https:\/\/www.greytrix.com\/blogs\/sagecrm\/#\/schema\/person\/e7ff1c8f4763b47730d6bc5e74d59c1f\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.greytrix.com\/blogs\/sagecrm\/2015\/11\/05\/javascript-to-print-amount-in-words\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.greytrix.com\/blogs\/sagecrm\/2015\/11\/05\/javascript-to-print-amount-in-words\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.greytrix.com\/blogs\/sagecrm\/2015\/11\/05\/javascript-to-print-amount-in-words\/#primaryimage\",\"url\":\"http:\/\/www.greytrix.com\/blogs\/sagecrm\/wp-content\/uploads\/2015\/11\/1.jpg\",\"contentUrl\":\"http:\/\/www.greytrix.com\/blogs\/sagecrm\/wp-content\/uploads\/2015\/11\/1.jpg\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.greytrix.com\/blogs\/sagecrm\/2015\/11\/05\/javascript-to-print-amount-in-words\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.greytrix.com\/blogs\/sagecrm\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"JavaScript to print Amount (In Words)\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.greytrix.com\/blogs\/sagecrm\/#website\",\"url\":\"https:\/\/www.greytrix.com\/blogs\/sagecrm\/\",\"name\":\"Sage CRM \u2013 Tips, Tricks and Components\",\"description\":\"Explore the possibilities with Sage CRM insights through our comprehensive blogs. As a leading Sage partner, Greytrix helps businesses maximize their Sage CRM potential with its rich expertise and immense knowledge. Here, you will find blogs that feature expert advice, tips &amp; tricks, best practices, and comprehensive guides on customizing and configuring Sage CRM for your business. Stay informed with our regular updates and expert insights!\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.greytrix.com\/blogs\/sagecrm\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.greytrix.com\/blogs\/sagecrm\/#\/schema\/person\/e7ff1c8f4763b47730d6bc5e74d59c1f\",\"name\":\"greysagecrm\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.greytrix.com\/blogs\/sagecrm\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/c3b4325cb326e36467f945b9b9adf2bb85e907fe092d42eb36b39743b492e626?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/c3b4325cb326e36467f945b9b9adf2bb85e907fe092d42eb36b39743b492e626?s=96&d=mm&r=g\",\"caption\":\"greysagecrm\"},\"url\":\"https:\/\/www.greytrix.com\/blogs\/sagecrm\/author\/greysagecrm\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"JavaScript to print Amount (In Words) - Sage CRM \u2013 Tips, Tricks and Components","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.greytrix.com\/blogs\/sagecrm\/2015\/11\/05\/javascript-to-print-amount-in-words\/","og_locale":"en_US","og_type":"article","og_title":"JavaScript to print Amount (In Words) - Sage CRM \u2013 Tips, Tricks and Components","og_description":"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\u2019s life has come to an ease. We have already posted few blogs about writing JavaScript codes in\u00a0.js files and calling the same in\u2026 Read More &raquo;","og_url":"https:\/\/www.greytrix.com\/blogs\/sagecrm\/2015\/11\/05\/javascript-to-print-amount-in-words\/","og_site_name":"Sage CRM \u2013 Tips, Tricks and Components","article_published_time":"2015-11-05T07:14:23+00:00","article_modified_time":"2022-11-04T10:14:19+00:00","og_image":[{"url":"http:\/\/www.greytrix.com\/blogs\/sagecrm\/wp-content\/uploads\/2015\/11\/1.jpg","type":"","width":"","height":""}],"author":"greysagecrm","twitter_card":"summary_large_image","twitter_misc":{"Written by":"greysagecrm","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.greytrix.com\/blogs\/sagecrm\/2015\/11\/05\/javascript-to-print-amount-in-words\/","url":"https:\/\/www.greytrix.com\/blogs\/sagecrm\/2015\/11\/05\/javascript-to-print-amount-in-words\/","name":"JavaScript to print Amount (In Words) - Sage CRM \u2013 Tips, Tricks and Components","isPartOf":{"@id":"https:\/\/www.greytrix.com\/blogs\/sagecrm\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.greytrix.com\/blogs\/sagecrm\/2015\/11\/05\/javascript-to-print-amount-in-words\/#primaryimage"},"image":{"@id":"https:\/\/www.greytrix.com\/blogs\/sagecrm\/2015\/11\/05\/javascript-to-print-amount-in-words\/#primaryimage"},"thumbnailUrl":"http:\/\/www.greytrix.com\/blogs\/sagecrm\/wp-content\/uploads\/2015\/11\/1.jpg","datePublished":"2015-11-05T07:14:23+00:00","dateModified":"2022-11-04T10:14:19+00:00","author":{"@id":"https:\/\/www.greytrix.com\/blogs\/sagecrm\/#\/schema\/person\/e7ff1c8f4763b47730d6bc5e74d59c1f"},"breadcrumb":{"@id":"https:\/\/www.greytrix.com\/blogs\/sagecrm\/2015\/11\/05\/javascript-to-print-amount-in-words\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.greytrix.com\/blogs\/sagecrm\/2015\/11\/05\/javascript-to-print-amount-in-words\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.greytrix.com\/blogs\/sagecrm\/2015\/11\/05\/javascript-to-print-amount-in-words\/#primaryimage","url":"http:\/\/www.greytrix.com\/blogs\/sagecrm\/wp-content\/uploads\/2015\/11\/1.jpg","contentUrl":"http:\/\/www.greytrix.com\/blogs\/sagecrm\/wp-content\/uploads\/2015\/11\/1.jpg"},{"@type":"BreadcrumbList","@id":"https:\/\/www.greytrix.com\/blogs\/sagecrm\/2015\/11\/05\/javascript-to-print-amount-in-words\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.greytrix.com\/blogs\/sagecrm\/"},{"@type":"ListItem","position":2,"name":"JavaScript to print Amount (In Words)"}]},{"@type":"WebSite","@id":"https:\/\/www.greytrix.com\/blogs\/sagecrm\/#website","url":"https:\/\/www.greytrix.com\/blogs\/sagecrm\/","name":"Sage CRM \u2013 Tips, Tricks and Components","description":"Explore the possibilities with Sage CRM insights through our comprehensive blogs. As a leading Sage partner, Greytrix helps businesses maximize their Sage CRM potential with its rich expertise and immense knowledge. Here, you will find blogs that feature expert advice, tips &amp; tricks, best practices, and comprehensive guides on customizing and configuring Sage CRM for your business. Stay informed with our regular updates and expert insights!","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.greytrix.com\/blogs\/sagecrm\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.greytrix.com\/blogs\/sagecrm\/#\/schema\/person\/e7ff1c8f4763b47730d6bc5e74d59c1f","name":"greysagecrm","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.greytrix.com\/blogs\/sagecrm\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/c3b4325cb326e36467f945b9b9adf2bb85e907fe092d42eb36b39743b492e626?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/c3b4325cb326e36467f945b9b9adf2bb85e907fe092d42eb36b39743b492e626?s=96&d=mm&r=g","caption":"greysagecrm"},"url":"https:\/\/www.greytrix.com\/blogs\/sagecrm\/author\/greysagecrm\/"}]}},"_links":{"self":[{"href":"https:\/\/www.greytrix.com\/blogs\/sagecrm\/wp-json\/wp\/v2\/posts\/11387","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.greytrix.com\/blogs\/sagecrm\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.greytrix.com\/blogs\/sagecrm\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.greytrix.com\/blogs\/sagecrm\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.greytrix.com\/blogs\/sagecrm\/wp-json\/wp\/v2\/comments?post=11387"}],"version-history":[{"count":1,"href":"https:\/\/www.greytrix.com\/blogs\/sagecrm\/wp-json\/wp\/v2\/posts\/11387\/revisions"}],"predecessor-version":[{"id":26731,"href":"https:\/\/www.greytrix.com\/blogs\/sagecrm\/wp-json\/wp\/v2\/posts\/11387\/revisions\/26731"}],"wp:attachment":[{"href":"https:\/\/www.greytrix.com\/blogs\/sagecrm\/wp-json\/wp\/v2\/media?parent=11387"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.greytrix.com\/blogs\/sagecrm\/wp-json\/wp\/v2\/categories?post=11387"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.greytrix.com\/blogs\/sagecrm\/wp-json\/wp\/v2\/tags?post=11387"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}