Formating String when execute String.valueOf(My_field)

Four Stars

Formating String when execute String.valueOf(My_field)

Hello.
First i have a integer value i want to string. Then i use String.valueOf(My_Field).
But if the value is 3 i get in my string "3" or i would like to have "03".
An idea please.
I surch for a Format.... method but no results yet.
Thanks
Community Manager

Re: Formating String when execute String.valueOf(My_field)

Hello
Try
String.valueOf(My_Field).length()<2?"0"+String.valueOf(My_Field):String.valueOf(My_Field)

Best regards

shong
----------------------------------------------------------
Talend | Data Agility for Modern Business
One Star

Re: Formating String when execute String.valueOf(My_field)

I use this in tMap to convert a integer between 0 to 99, to a 2 charcaters String
StringHandling.CHANGE(String.format("%2.0f",ROW1.FIELD)," ","0");
"%2.0f" is format of java printf syntaxe
String.format is talend function
StringHandling.CHANGE is talend function
Four Stars

Re: Formating String when execute String.valueOf(My_field)

Shong and SDjecepap i thank you very much.