Java DoubleAdder floatValue()方法及示例

来源:这里教程网 时间:2026-02-17 20:47:29 作者:

Java DoubleAdder floatValue()方法及示例

java.DoubleAdder.floatValue() 是java中的一个内置方法,它在缩小原始转换后将sum()作为 浮点数 返回。当该类的对象被创建时,其初始值为零。

语法

public float floatValue()

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

返回值: 该方法在转换为float数据类型后返回该对象所代表的数字值。

下面的程序说明了上述方法。

// Program to demonstrate the floatValue() method  import java.lang.*;import java.util.concurrent.atomic.DoubleAdder;  public class GFG {    public static void main(String args[])    {        DoubleAdder num = new DoubleAdder();          // add operation on num        num.add(11);        num.add(10);          // floatValue() operation on variable num        num.floatValue();          // Print after floatValue() operation        System.out.println("the value after floatValue() is: " + num);    }}

输出:

the value after floatValue() is: 21.0
// Program to demonstrate the floatValue() method  import java.lang.*;import java.util.concurrent.atomic.DoubleAdder;  public class GFG {    public static void main(String args[])    {        DoubleAdder num = new DoubleAdder();          // add operation on num        num.add(10);          // floatValue() operation on variable num        num.floatValue();          // Print after floatValue() operation        System.out.println("the value after floatValue() is: " + num);    }}

输出:

the value after floatValue() is: 10.0

参考资料 : https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/atomic/DoubleAdder.html#floatValue-

相关推荐