Friday, February 15, 2013

Converting Dollars and Cents to Words in GP Report Writer


We had a request from a customer to convert the Dollars and Cents to words in GP reports. There is a function RW_ConvertToWordsAndNumbers() readily available in GP report writer. The problem with this function  RW_ConvertToWordsAndNumbers()  is it will convert only the dollar amount to words and not the cent amount.

Example: If you pass $250.75 to this function RW_ConvertToWordsAndNumbers(), it will give you Two Hundred Fifty Dollars and 75 cents.

For this case, customer has requested to show Two Hundred Fifty Dollars and Seventy Five Cents in the report.

We can achieve this functionality by creating calculated fields in Report Writer.

[Cal]_amount = Pass your amount here

{----Split Dollars and Cents----}
[Cal]_dollars = RW_Truncate ([Cal]_amount, 0, 0)
[Cal]_cents = ([Cal]_amount - [Cal]_dollars) * 100.0

{---Convert only Dollars into words---}
[Cal]_dollarinstring = RW_ConvertToWordsAndNumbers ([Cal]_dollars, 0, 0)
[Cal]_centpos = RW_Pos ([Cal]_ dollarinstring, "00", 1)
[Cal]_amountinwords1= RW_Left ([Cal]_ dollarinstring, [Cal]_ centpos - 1)
[Cal]_amountinwords2 = RW_Substring ([Cal]_ dollarinstring, [Cal]_ centpos + 2, 20)

{---Convert only Cents into words---}
[Cal]_centinwords1 = RW_ConvertToWordsAndNumbers ([Cal]_cents,"_", 0)
[Cal]_length = RW_Length ([Cal]_centinwords1)
[Cal]_centinwords2 = RW_Left ([Cal]_centinwords1, [Cal]_length - 4)
[Cal]_amountinwords3 = RW_Trim ([Cal]_centinwords2, 3, " ")

{---Concatenating Dollars and Cents---}
[Cal]_finalamountinwords = [Cal]_amountinwords1+ [Cal]_amountinwords3 +                                                                                                      [Cal]_amountinwords2

Place the calculated field [Cal]_finalamountinwords in the report to view the dollars and cents in words.

Hope this helps!!!

No comments:

Post a Comment