久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

Java中的浮點和雙精度數據類型

Float and double datatype in Java(Java中的浮點和雙精度數據類型)
本文介紹了Java中的浮點和雙精度數據類型的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

float 數據類型是單精度 32 位 IEEE 754 浮點數,double 數據類型是雙精度 64 位 IEEE 754 浮點數.

The float data type is a single-precision 32-bit IEEE 754 floating point and the double data type is a double-precision 64-bit IEEE 754 floating point.

這是什么意思?我什么時候應該使用 float 而不是 double 或反之亦然?

What does it mean? And when should I use float instead of double or vice-versa?

推薦答案

維基百科頁面這是一個很好的起點.

總結一下:

  • float 用 32 位表示,有 1 個符號位、8 位指數和 23 位有效數字(或從科學記數法數得出的數字:2.33728*1012;33728 是有效位).

  • float is represented in 32 bits, with 1 sign bit, 8 bits of exponent, and 23 bits of the significand (or what follows from a scientific-notation number: 2.33728*1012; 33728 is the significand).

double 用 64 位表示,有 1 個符號位、11 位指數和 52 位有效位.

double is represented in 64 bits, with 1 sign bit, 11 bits of exponent, and 52 bits of significand.

默認情況下,Java 使用 double 來表示它的浮點數(所以文字 3.14 的類型是 double).它也是可以為您提供更大數字范圍的數據類型,因此我強烈建議使用它而不是 float.

By default, Java uses double to represent its floating-point numerals (so a literal 3.14 is typed double). It's also the data type that will give you a much larger number range, so I would strongly encourage its use over float.

可能有某些庫實際上會強制您使用 float,但總的來說 - 除非您可以保證您的結果足夠小以適合 float's 規定范圍,那么最好選擇與 double.

There may be certain libraries that actually force your usage of float, but in general - unless you can guarantee that your result will be small enough to fit in float's prescribed range, then it's best to opt with double.

如果您需要準確性 - 例如,您不能有不準確的十進制值(例如 1/10 + 2/10),或者您正在做任何事情 與貨幣(例如,在系統中表示 $10.33),然后使用 BigDecimal,它可以支持任意數量的精度并優雅地處理此類情況.

If you require accuracy - for instance, you can't have a decimal value that is inaccurate (like 1/10 + 2/10), or you're doing anything with currency (for example, representing $10.33 in the system), then use a BigDecimal, which can support an arbitrary amount of precision and handle situations like that elegantly.

這篇關于Java中的浮點和雙精度數據類型的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

How to wrap text around components in a JTextPane?(如何在 JTextPane 中的組件周圍環繞文本?)
MyBatis, how to get the auto generated key of an insert? [MySql](MyBatis,如何獲取插入的自動生成密鑰?[MySql])
Inserting to Oracle Nested Table in Java(在 Java 中插入 Oracle 嵌套表)
Java: How to insert CLOB into oracle database(Java:如何將 CLOB 插入 oracle 數據庫)
Why does Spring-data-jdbc not save my Car object?(為什么 Spring-data-jdbc 不保存我的 Car 對象?)
Use threading to process file chunk by chunk(使用線程逐塊處理文件)
主站蜘蛛池模板: 欧美成人a∨高清免费观看 老司机午夜性大片 | 99久久国产免费 | 免费在线视频精品 | 欧美电影一区 | 999热精品 | 欧美一区二区三区视频 | 99久久中文字幕三级久久日本 | 激情五月婷婷在线 | 日日夜夜天天 | 91精品国产综合久久精品图片 | 久久天天 | 91麻豆精品国产91久久久久久久久 | a视频在线观看 | 国产精品高潮呻吟久久久久 | 国产精品一区二区电影 | 蜜桃精品视频在线 | 日韩不卡在线观看 | 丁香综合| 又黄又色 | 久久久123 | 综合色婷婷 | 国产视频一区在线 | 欧美xxxⅹ性欧美大片 | 国产一级久久久久 | 日本在线精品视频 | 中文字幕乱码一区二区三区 | 久久精品福利视频 | 久久久久国产一区二区三区 | 999久久久久久久久6666 | 欧美成年人网站 | 日韩久草 | 天天插天天搞 | 欧美激情一区二区三级高清视频 | 亚洲一二三区精品 | 国产色婷婷精品综合在线播放 | 日韩av福利在线观看 | 99久久精品国产毛片 | 久久se精品一区精品二区 | 欧美一级黄色片在线观看 | 日韩在线一区二区三区 | 少妇精品久久久久久久久久 |