Page 1 of 1

Removing leading '0' while decimal to varchar conversion

Posted: Tue Mar 24, 2015 7:17 pm
by udayanguha
Hi,
I have a decimal field of length (38,0) in my source table. In the target I want to put it as a varchar field.
I am using the TRIM function to remove leading '0's from the source field but '0's are not getting removed. Now I am using DecimalToString function which is working fine.
But I am still curious to know why trim function below is not working.

trim(field,"0","L")

Posted: Tue Mar 24, 2015 10:40 pm
by ray.wurlod
Probably there are non leading zeroes because the actual leading character is a space (" ") occupying the sign position.

Posted: Wed Mar 25, 2015 6:57 am
by udayanguha
I think you are right Ray, because I have a leading space for sign. So that means I first need to remove leading space and then leading '0's or rather stick to DecimalTo String with suppress zero.

Thanks Ray. I during this whole time saw this leading Space in the file and it never struck to me that '0's are not leading now. My bad!!

Posted: Wed Mar 25, 2015 6:59 am
by qt_ky
Also keep in mind that negative numbers will lead with a negative sign, not a space...

Re: Removing leading '0' while decimal to varchar conversion

Posted: Fri Jun 26, 2015 1:10 am
by weiyi_will
I ever avoided the leading zero issue by use VarChar from reading data from DB.