java中Integer转Float总结以及BigDecimal 转float

一.先将Integer转化成int类型,在强制转float类型()

例:

Integer str = new Integer(20);

     int i = str.intValue();

     float rr = (float)i;

输出结果为:20.0

二.将Integer类型转成String类型,在转化成float类型

例:

   Integer str = 2056;

    String format = new BigDecimal(String.valueOf(str)).toString();

   float rr = Float.valueOf(format);

输出结果为20.0

三.BigDecimal 转float

例:

   BigDecimal tt = new BigDecimal(50) ;

    float kk = tt.floatValue();

输出结果:50.0

以上均本人亲自测试,如不符合,请仔细检查


 上一篇
Java中Date与String的相互转换 Java中Date与String的相互转换
我们在注册网站的时候,往往需要填写个人信息,如姓名,年龄,出生日期等,在页面上的出生日期的值传递到后台的时候是一个字符串,而我们存入数据库的时候确需要一个日期类型,反过来,在页面上显示的时候,需要从数据库获取出生日期,此时该类型为日期类型,
2019-01-20
下一篇 
Statement cancelled due to timeout or client request Statement cancelled due to timeout or client request
Caused by: com.mysql.jdbc.exceptions.MySQLTimeoutException: Statement cancelled due to timeout or client request at com
2019-01-20
  目录