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)