Friday, August 31, 2012

Crystal Reports : Why use Currency?

In any aging or "invoice" report, you will undoubtedly need to sum up some dollar amounts.
This can be tricky, depending on how the back end database is storing the data.

In a perfect world, you are using SQL server and the dollar amount field is declared as CURRENCY.

In the real world, however, the value may be stored at plaintext, which as we all know, cannot be summarized as a numerical value.

Now, we can convert the plaintext INVOICES.AMOUNT into a number by using TONUMBER(INVOICES.AMOUNT).

A better solution might be to use the TOCURRENCY() function, which will not only convert our plaintext to a numerical value, it will also provide the expected number of decimal places, and also display itself with the currency symbol ($).

Just a quick shortcut. You could do the same thing with a combination of the TONUMBER() function and field formatting. But I've found that when dealing with dollar amounts, CURRENCY is always preferable to NUMERIC.

No comments: