1. 程式人生 > >在Talend 的tMap元件中資料型別轉換函式總結(一)

在Talend 的tMap元件中資料型別轉換函式總結(一)

1.1 字串與數值型別相互轉換 1.1.1 字串轉為浮點型、整形 1)Float.parseFloat(row3.working_time ) Float.valueOf(String s) Float.valueOf(int s) 2)Integer.parseInt(out4.unit_qty) 3)Long.parseLong(row2.m1_shipment_qty) 4)Double.parseDouble(String s)

1.2.1 數值型轉換為字串 1)String.valueOf(boolean b) : 將 boolean 變數 b 轉換成字串 2)String.valueOf(char c) : 將 char 變數 c 轉換成字串 3)String.valueOf(char[] data) : 將 char 陣列 data 轉換成字串 4)String.valueOf(char[] data, int offset, int count) : 將 char 陣列 data 中 由 data[offset] 開始取 count 個元素 轉換成字串 5)String.valueOf(double d) : 將 double 變數 d 轉換成字串 6)String.valueOf(float f) : 將 float 變數 f 轉換成字串 7)String.valueOf(int i) : 將 int 變數 i 轉換成字串 8)String.valueOf(long l) : 將 long 變數 l 轉換成字串 9)String.valueOf(Object obj) : 將 obj 物件轉換成 字串, 等於 obj.toString() eg:int shift; String.valueOf(row1.shift) ((String)globalMap.get(“emailTopMessage_ppms”)) globalMap.put(“messageVariable_product_short_series”, messageVariable_product_short_series); 1.2.2 由 String 轉換成 數字的基本資料型態 要將 String 轉換成基本資料型態轉 大多需要使用基本資料型態的包裝類別 比如說 String 轉換成 byte 可以使用 Byte.parseByte(String s) 這一類的方法如果無法將 s 分析 則會丟出 NumberFormatException 1)byte : Byte.parseByte(String s) : 將 s 轉換成 byte Byte.parseByte(String s, int radix) : 以 radix 為基底 將 s 轉換為 byte 比如說 Byte.parseByte(“11”, 16) 會得到 17 2)double : Double.parseDouble(String s) : 將 s 轉換成 double 3)float : Float.parseFloat(String s) : 將 s 轉換成 float 4)int : Integer.parseInt(String s) : 將 s 轉換成 int 5)long : Long.parseLong(String s):將 s 轉換成 long