當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


Java Double floatVlaue()用法及代碼示例


Double 類的 floatVlaue() 方法返回此 double 對象的浮點值。

用法

public float floatValue()

參數

NA

返回值

floatValue() 方法返回轉換為 float 類型的 double 值。

例子1

public class Double_floatValueMethodExample1 {
    public static void main(String[] args) {

        Double double1 = 55.05587687687;

        Double double2= new Double(double1);

        //widening the float object

        float f1= double2.floatValue();

        System.out.println(double1+ " after converted to float becomes:"+f1);

    }

}

輸出:

55.05587687687 after converted to float becomes:55.055878

例子2

import java.lang.*;
public class Double_floatValueMethodExample2 {

        public static void main(String[] args) {


            //passing negative integer

            double d1 = 98797987876875698796.63655768769857694;

            Double d2= new Double(d1);

            System.out.println("Double value = "+d2);

            //Converting Double into float

           float f1 =d2.floatValue();

            System.out.println("Float value  = "+f1);

        }

    }

輸出:

Double value = 9.87979878768757E19
Float value  = 9.879799E19

例子3

import java.lang.*;
public class Double_floatValueMethodExample3 {
        public static void main(String[] args) {

            double d1 = 98797987876875698796.63655768769857694;
            System.out.println("Double value = "+d1);

            //Converting Double into float

           float f1 =d1.floatValue();

            System.out.println("Float value  = "+f1);

        }

    }

輸出:

Error:(19, 24) java:double cannot be dereferenced






相關用法


注:本文由純淨天空篩選整理自 Java Double floatVlaue() method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。