RW – Getting RW_ConvertToWordsAndNumbers() to show cents in words

David Meego - Click for blog homepageThis is a reposting of an article I originally wrote on my Developing for Dynamics GP blog.

A little while ago I wrote an article about how to get the RW_ConvertToWordsAndNumbers() report writer user defined function to work correctly for both originating and functional currency views. Today, a comment was added to that article asking about how to get the RW_ConvertToWordsAndNumbers() function to return the cents in words rather than numbers.

Usually the function will convert the dollar amount into words but the cent amount is shown as numbers.

For example: Using the amount 1,234.56 and the currency ID Z-US$ will return:

One Thousand Two Hundred Thirty Four Dollars and 56 Cents

However, the request was to get the following, with the cents in words:

One Thousand Two Hundred Thirty Four Dollars and Fifty Six Cents

None of the available Report Writer (RW) functions which can convert amounts to words can achieve this result. So…

 


I decided to write some Dexterity code (using the Runtime Execute window in the Support Debugging Tool) to manipulate the values returned from the function to achieve the desired end result. This code is written only using RW functions so it can be transferred to calculated fields in the report writer easily.

The concept is to separate the dollars amount from the cents amount and then pass the cents amount to the function as though it was a dollar amount.  We then take back the resulting strings and splice them back together to get the result we wanted.

Dexterity Code


local currency l_amount, l_dollars, l_cents;
local string l_currency;
local string l_dollarwords, l_tempwords, l_tempwords2, l_centwords;
local string l_amountwords, l_leftwords, l_rightwords;
local integer l_length, l_position;

{ Input Values }
l_amount = 1234.56;
l_currency = "Z-US$";

{ Separate Dollars and Cents }
l_dollars = RW_Truncate(l_amount, 0, 0);
l_cents = (l_amount - l_dollars) * 100.0;

{ Convert Dollars and split on 00 Cents }
l_dollarwords = RW_ConvertToWordsAndNumbers(l_dollars,l_currency,0);
l_position = RW_Pos(l_dollarwords, "00", 1);
l_leftwords = RW_Left(l_dollarwords, l_position - 1);
l_rightwords = RW_Substring(l_dollarwords, l_position + 2, 20);

{ Convert Cents and extract Cent amount in words }
l_tempwords = RW_ConvertToWordsAndNumbers(l_cents,"_",0);
l_length = RW_Length(l_tempwords);
l_tempwords2 = RW_Left(l_tempwords, l_length - 4);
l_centwords = RW_Trim(l_tempwords2, 3, " ");

{ Combine results back together }
l_amountwords = l_leftwords + l_centwords + l_rightwords;

warning l_amountwords;

I then took the same logic and formulas into report writer as calculated fields and created an updated version of the report from the original post (see attached).

Please see the link below for the original article:

An example package of the v10.0 POP Purchase Order Other Form is attached at the bottom of the article.

Hope you find this useful.

David

POP Purchase Order Other Form.zip

05-Jul-2010: Also look at new function in the post: Announcing Report Writer Function RW_ConvertToWordsAndNumbersParse.

This article was originally posted on the Developing for Dynamics GP Blog and has been reposted on http://www.winthropdc.com/blog.

9 thoughts on “RW – Getting RW_ConvertToWordsAndNumbers() to show cents in words

  1. Thanks David.
    I was referring this function to one of my friend and the same gap was reported by him. I could not give him any solution for that as I was involved in a different task.
    This was badly needed by him and I can now deviate him to this article.
    Thanks
    Vaidy

    Like

  2. thanks dave. Now i want to add one string "Only" at the end of amount in words. for eg : six thousand dollars only..
    pls help

    Like

  3. Manoj
    If you are using VBA to get this working, you will need to add the "only" text from VBA.  The VBA code runs after the Report Writer has completed the section being printed. You cannot the results from VBA code in RW calculated fields.
    David

    Like

  4. thanx for your reply. I am not using any VBA code.I am using the calculated fields in report writer. I want to add "only" string to string B. Is it possible through calculated fields ?

    Like

  5. Hi Manoj
    String calculated fields are limited to 80 characters.  if the contents of String B are longer than 75 characters there will not be room to add " only".  
    So, no.  This method is not going to work 100% of the time.
    David

    Like

Please post feedback or comments

This site uses Akismet to reduce spam. Learn how your comment data is processed.