floatValue java_Java Number.floatValue()用法及代码示例

java.lang.Number.floatValue()是java中的一个内置方法,该方法返回转换为float数据类型的指定数字的值。这可能涉及舍入或截断。

用法:

public abstract float floatValue()

参数:此方法不接受任何参数。

返回值:转换为float类型后,此方法返回此对象表示的数值。

以下示例程序旨在说明Number.floatValue()方法:

示例1:

// Below program demonstrate the

// Number.floatValue() method

public class gfg {

public static void main(String[] args)

{

// number with integer datatype

Integer x = new Integer(1785423456);

// print the value as float

System.out.println(x.floatValue());

// number with double datatype

Double y = new Double(97854876);

// print the value as float

System.out.println(y.floatValue());

}

}

输出:

1.78542349E9

9.785488E7

示例2:

// Below program demonstrate the

// Number.floatValue() method

public class gfg {

public static void main(String[] args)

{

// number with integer datatype

Integer x = new Integer(456);

// print the value as float

System.out.println(x.floatValue());

// number with double datatype

Double y = new Double(96);

// print the value as float

System.out.println(y.floatValue());

}

}

输出:

456.0

96.0

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值