Losing leading “0” Zeros when converting to integer from string

Highlighted
Six Stars

Losing leading “0” Zeros when converting to integer from string

Hello,

When I am converting a String to an Integer, I am losing the leading zeros from my variable.
I tried this 'Integer.parseInt((row1.date.length()==5)?"0"+row1.date:row1.date ) ' but it didin't work

Exemple :
Input data : '012005'
In Output data I have : '12005'

Someone can help me please?
Thank you


Accepted Solutions
Ten Stars

Re: Losing leading “0” Zeros when converting to integer from string

There's no notion of leading zeroes when storing numbers in a numeric format. If you need to preserve zeroes throughout the job, it has to be a String. If this is only an issue when you output the data at the end, you can convert back to a String, padding the value with leading zeroes as needed.

All Replies
Nine Stars

Re: Losing leading “0” Zeros when converting to integer from string

Hi Maria,
As per my understanding, if you convert any value to number it will remove '0' zero in the begin. Because there is no value for '0' zero if it is before some number, if zero '0' present after number then it has some value.

Regards,
Veeru
Veeru Boppudi
Ten Stars

Re: Losing leading “0” Zeros when converting to integer from string

There's no notion of leading zeroes when storing numbers in a numeric format. If you need to preserve zeroes throughout the job, it has to be a String. If this is only an issue when you output the data at the end, you can convert back to a String, padding the value with leading zeroes as needed.

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

Tutorial

Introduction to Talend Open Studio for Data Integration.

Watch