在路上

 找回密码
 立即注册
在路上 站点首页 学习 查看内容

Java中各种数字类型转换成字符串型

2016-12-20 13:11| 发布者: zhangjf| 查看: 519| 评论: 0

摘要: Java中各种数字类型转换成字符串型: String s = String.valueOf( value); // 其中 value 为任意一种数字类型。 字符串型转换成各种数字类型: String str = "120"; byte b = Byte.parseByte( str ); short t = ...

Java中各种数字类型转换成字符串型:
String s = String.valueOf( value); // 其中 value 为任意一种数字类型。
字符串型转换成各种数字类型:
String str = "120";
byte b = Byte.parseByte( str );
short t = Short.parseShort( str );
int i = Integer.parseInt( str );
long l = Long.parseLong( str );
Float f = Float.parseFloat( str );
Double d = Double.parseDouble( str );

数字类型与数字类对象之间的转换:

byte b = 120;
Byte bo = new Byte( b );
b = bo.byteValue();

short t = 120;
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();

最新评论

小黑屋|在路上 ( 蜀ICP备15035742号-1 

;

GMT+8, 2025-7-7 21:01

Copyright 2015-2025 djqfx

返回顶部