java各種數字型別與字串的轉換

2021-06-19 02:28:59 字數 1062 閱讀 4598

各種數字型別轉換成字串型: 

string s = string.valueof( value); // 其中 value 為任意一種數字型別。 

字串型轉換成各種數字型別: 

string s = "169"; 

byte b = byte.parsebyte( s ); 

short t = short.parseshort( s ); 

int i = integer.parseint( s ); 

long l = long.parselong( s ); 

float f = float.parsefloat( s ); 

double d = double.parsedouble( s ); 

數字型別與數字類物件之間的轉換: 

byte b = 169; 

byte bo = new byte( b ); 

b = bo.bytevalue(); 

short t = 169; 

short to = new short( t ); 

t = to.shortvalue(); 

int i = 169; 

b = bo.bytevalue(); 

short t = 169; 

short to = new short( t ); 

t = to.shortvalue(); 

int i = 169; 

integer io = new integer( i ); 

i = io.intvalue(); 

long l = 169; 

long lo = new long( l ); 

l = lo.longvalue(); 

float f = 169f; 

float fo = new float( f ); 

f = fo.floatvalue(); 

double d = 169f; 

double dobj = new double( d ); 

d = dobj.doublevalue();

各種數字型別轉換成字串型 JAVA

各種數字型別轉換成字串型 string s string.valueof value 其中 value 為任意一種數字型別。字串型轉換成各種數字型別 string s 169 byte b byte.parsebyte s short t short.parseshort s int i integ...

各種數字型別轉換成字串型

各種數字型別轉換成字串型 各種數字型別轉換成字串型 string s string.valueof value 其中 value 為任意一種數字型別。字串型轉換成各種數字型別 string s 169 byte b byte.parsebyte s short t short.parseshort ...

各種數字型別轉換成字串型

各種數字型別轉換成字串型 string s string.valueof value 其中 value 為任意一種數字型別。字串型轉換成各種數字型別 string s 169 byte b byte.parsebyte s short t short.parseshort s int i integ...