How to convert between different datatypes

The following table is a set of Java and Talend methods that allow conversion between
different datatypes. This is by no means an exhaustive list, but will cover many of type
conversions that you will encounter. You can use them in the tMap, tXMLmap or tJava component for example.

 

 

From typeTo TypeExample
StringIntegerInteger.parseInt(row1.myString)
StringInteger(new Integer(row1.myString)).toString()
StringDateTalendDate.parseDate("dd-MMyyyy",
row1.myString)
StringBigDecimalnew BigDecimal(row1.myString) where
myString can include decimal places. For example,
99.00
StringFloatFloat.parseFloat(row1.myString)
StringLongLong.parseLong(row1.myString)
IntegerStringvariable+"" or variable.toString()
DateStringTalendDate.formatDate("yy-MM-dd",
row1.myDate)
BigDecimalStringrow1.myBigDecimal.toString()
FloatStringrow1.myFloat.toString()
LongStringrow1.myLong.toString()
IntegerLongrow1.myInteger.longValue()
IntegerBigDecimalnew BigDecimal(row1.myInteger)
IntegerFloatnew Float(row1.myInteger)
FloatIntegerTo do this conversion you need to decide on a
rounding methods such as Math.round(),
Math.ceil(), Math.floor() and then cast
the result to Integer.
BigDecimalIntegerAs with Float, BigDecimal can have decimal places,
so will need to be rounded prior to casting to
Integer.
FloatBigDecimalnew BigDecimal(Float.toString(row1.
myFloat))

 

 

3 Comments

Leave a Reply

Assign a menu in the Left Menu options.
Assign a menu in the Right Menu options.