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

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.

View solution in original post


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.

View solution in original post

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 2

Part 2 of a series on Context Variables

Blog

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