- PARSE-AS-CURRENCY
- TRIM, LTRIM and RTRIM
PARSE-AS-CURRENCY
The PARSE-AS-CURRENCY is a directive for parsing a currency value that is a string representation of locale currency into a number. Syntaxparse-as-currency <source> <destination> [<locale>]
PARSE-AS-CURRENCY can be used to parse a string representation of currency into a number. If locale is not specified in the directive, a default of ‘en_US’ is assumed.
When the directive is unable to parse the currency, an error record is generated.
Following are few examples of parsing currency into number:
Code
TRIM, LTRIM and RTRIM
The TRIM, LTRIM, and RTRIM directives trim whitespace from both sides, left side or right side of a string values they are applied to. SyntaxCode
| Character | Description |
|---|---|
| \t | Character tabulation |
| \n | Line Feed (LF) |
| \u000B | Line Tabulation |
| \f | Form Feed (FF) |
| \r | Carriage Return (CR) |
| ” “ | Space |
| \u0085 | Next line (NEL) |
| \u00A0 | No Break Space |
| \u1680 | OGHAM Space Mark |
| \u180E | Mongolian Vowel Separator |
| \u2000 | EN Quad |
| \u2001 | EM Quad |
| \u2002 | EN Space |
| \u2003 | EM Space |
| \u2004 | Three Per EM space |
| \u2005 | Four Per EM space |
| \u2006 | Six Per EM space |
| \u2007 | Figure Space |
| \u2008 | Puncatuation Space |
| \u2009 | Thin Space |
| \u200A | Hair Space |
| \u2028 | Line Separator |
| \u2029 | Paragraph Separator |
| \u202F | Narrow No-Break Space |
| \u205F | Medium Mathematical Space |
| \u3000 | Ideographic Space |
Use Case: Generating a Monthly Financial Report from Raw Transaction Data
Suppose, you are working on generating a monthly financial report from raw transaction data collected from a retail store. The data includes fields related to coupon redemptions, ticket amounts, churn scores, and customer lifetime values. To prepare this data for accurate reporting, you need to clean and format it using specific directives.Steps to Process the Data
- Trim Whitespace: Remove any leading or trailing whitespace from the relevant fields.
- Parse as Currency: Format the numerical values as currency in the
Belgian French locale (fr_BE). - Find and Replace: Standardise decimal notation by replacing commas with periods.
Directives for Data Transformation
In this case, in the mapping screen, create a custom field for which transformation is required and enrich it by adding a combination of directives as per your requirement. In this example the following directives are used to transform,amountRedeemedCoupons, averageAmountTicket and totalAmountTicket.
Code
| Directive | Description |
|---|---|
trim :amountRedeemedCoupons | Removes the space at the start and the end of the amountRedeemedCoupons. |
parse-as-currency :amountRedeemedCoupons :amountRedeemedCoupons 'fr_BE' | Converts the currency value of amountRedeemedCoupons to the standard currency value using the ‘fr_BE’ format. |
trim :averageAmountTicket | Removes the space at the start and the end of the averageAmountTicket. |
parse-as-currency :averageAmountTicket :averageAmountTicket 'fr_BE' | Converts the currency value of averageAmountTicket to the standard currency value using the ‘fr_BE’ format. |
find-and-replace churnscore s/,/./g | Finds commas in churnscore and replaces them with periods. |
find-and-replace lifetimeValue s/,/./g | Finds commas in lifetimeValue and replaces them with periods. |
trim :totalAmountTicket | Removes the space at the start and the end of the totalAmountTicket. |
parse-as-currency :totalAmountTicket :totalAmountTicket 'fr_BE' | Converts the currency value of totalAmountTicket to the standard currency value using the ‘fr_BE’ format. |