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

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)

I have very limited knowledge in java, please help. Thank you.

Tags (1)

2019 GARNER MAGIC QUADRANT FOR DATA INTEGRATION TOOL

Talend named a Leader.

Get your copy

OPEN STUDIO FOR DATA INTEGRATION

Kickstart your first data integration and ETL projects.

Download now

What’s New for Talend Summer ’19

Watch the recorded webinar!

Watch Now

Best Practices for Using Context Variables with Talend – Part 4

Pick up some tips and tricks with Context Variables

Blog

How Media Organizations Achieved Success with Data Integration

Learn how media organizations have achieved success with Data Integration

Read

Why Companies Move to the Cloud: 7 Success Stories

Learn how and why companies are moving to the Cloud

Read Now