17 Java語言基礎long與float的取值範圍誰大誰小

來源:互聯網
上載者:User

標籤:大於   ble   logs   數值   mis   can   ann   string   oat   

結論

 float的取值範圍比long大

驗證

 1 public class Test1_DataTypeConversion { 2  3     public static void main(String[] args) { 4  5         float f = 1.3f; 6         long l = 34; 7 //        l = f; 8 //        System.out.println(l); 9         //Type mismatch: cannot convert from float to long10         f = l;11         System.out.println(f);12 13     14     }15 16 }

 

進行混合運算的時候 byte short char 不會相互轉換 都會自動提升為int

取值範圍大小如下

char < int < long < float <double

double的取值範圍最大

float的取值範圍大於long

雖然 long的長度為8個位元組 float的長度為4個位元組 但是他們底層的儲存結構不同,所代表的數值大小也不同

17 Java語言基礎long與float的取值範圍誰大誰小

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.