## routine to convert number to fixed length with last digit=ASCII logic

Highlighted Six Stars

## routine to convert number to fixed length with last digit=ASCII logic

I need to write a routine to convert numbers to fixed length string, with the last digit following ASCII logic

for example: balance  is decimal(12,2), the value is  -415158.1, requested fixed length is 12, left pad 0 if the length is less than 12, and the . should be removed.

ASCII logic is:

if the last digit is 0 and it is negative, convert the last number to }

if the last digit is 1 and it is negative, convert the last number to J,

if the last digit is 2 and it is negative, convert the last number to K ...

if the last digit is 0 and it is positive, convert the last number to {

if the last digit is 1 and it is positive, convert the last number to A,

if the last digit is 2 and it is positive, convert the last number to B,....

This translate routine will have 3 variables, one decimal Balance, one integer length1, one integer decimal1

translate(-415158.1,12,2)   returns 00004151581}   (first make it to -415158.10)

translate(-415158.11,12,2) returns 00004151581J

translate(415158,12,2)       returns 00004151580{   (first make it to 415158.00)

Tags (1)

## OPEN STUDIO FOR DATA INTEGRATION

Kickstart your first data integration and ETL projects.

## Best Practices for Using Context Variables with Talend – Part 1

Learn how to do cool things with Context Variables

Blog

## Migrate Data from one Database to another with one Job using the Dynamic Schema

Find out how to migrate from one database to another using the Dynamic schema

Blog

## Best Practices for Using Context Variables with Talend – Part 4

Pick up some tips and tricks with Context Variables

Blog