> ## Documentation Index
> Fetch the complete documentation index at: https://docs.zeotap.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Scenario 2: Transformation of Currency Data Using a Custom Transformer

To transform incoming numeric data, such as currency, churn score and lifetime transaction value, from commas (US format) to decimals (European format) and remove any leading or trailing spaces, use the following transformations:

* 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.

**Syntax**

`parse-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:

```bash Code theme={null}
parse-as-currency :src :dst
parse-as-currency :src :dst 'en_US'
parse-as-currency :src :dst 'en_IE'
parse-as-currency :src :dst 'pl_PL'
parse-as-currency :src :dst 'ca_ES'
parse-as-currency :src :dst 'es_ES'
parse-as-currency :src :dst 'es_CO'
parse-as-currency :src :dst 'de_CH'
parse-as-currency :src :dst 'en_ZA'
parse-as-currency :src :dst 'en_GB'
parse-as-currency :src :dst 'fr_BE'
```

### 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.

**Syntax**

```bash Code theme={null}
trim <column>  
ltrim <column>  
rtrim <column>
```

The directive performs an in-place trimming of space in the value specified by the \<column>

The trim directives honors UNICODE space characters. Following are the characters that are recognised as spaces by TRIM, LTRIM and RTRIM.

| **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

1. **Trim Whitespace:** Remove any leading or trailing whitespace from the relevant fields.
2. **Parse as Currency:** Format the numerical values as currency in the `Belgian French locale (fr_BE)`.
3. **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`.

```bash Code theme={null}
trim :amountRedeemedCoupons
parse-as-currency :amountRedeemedCoupons :amountRedeemedCoupons 'fr_BE'
trim :averageAmountTicket
parse-as-currency :averageAmountTicket :averageAmountTicket 'fr_BE'
find-and-replace churnscore s/,/./g
find-and-replace lifetimeValue s/,/./g
trim :totalAmountTicket
parse-as-currency :totalAmountTicket :totalAmountTicket 'fr_BE'
```

Below are details of how each directive functions:

| **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.   |
