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

  • Data Integration
1 ACCEPTED SOLUTION

Accepted Solutions
Eight 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.
2 REPLIES
Six 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
Veeranjaneyulu Boppudi
Eight 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.