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

Java中的浮點(diǎn)和雙精度數(shù)據(jù)類型

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

問題描述

float 數(shù)據(jù)類型是單精度 32 位 IEEE 754 浮點(diǎn)數(shù),double 數(shù)據(jù)類型是雙精度 64 位 IEEE 754 浮點(diǎn)數(shù).

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.

這是什么意思?我什么時(shí)候應(yīng)該使用 float 而不是 double 或反之亦然?

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

推薦答案

維基百科頁面這是一個(gè)很好的起點(diǎn).

總結(jié)一下:

  • float 用 32 位表示,有 1 個(gè)符號(hào)位、8 位指數(shù)和 23 位有效數(shù)字(或從科學(xué)記數(shù)法數(shù)得出的數(shù)字: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 個(gè)符號(hào)位、11 位指數(shù)和 52 位有效位.

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

默認(rèn)情況下,Java 使用 double 來表示它的浮點(diǎn)數(shù)(所以文字 3.14 的類型是 double).它也是可以為您提供更大數(shù)字范圍的數(shù)據(jù)類型,因此我強(qiáng)烈建議使用它而不是 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.

可能有某些庫實(shí)際上會(huì)強(qiáng)制您使用 float,但總的來說 - 除非您可以保證您的結(jié)果足夠小以適合 float's 規(guī)定范圍,那么最好選擇與 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.

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

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.

這篇關(guān)于Java中的浮點(diǎn)和雙精度數(shù)據(jù)類型的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

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

相關(guān)文檔推薦

How to wrap text around components in a JTextPane?(如何在 JTextPane 中的組件周圍環(huán)繞文本?)
MyBatis, how to get the auto generated key of an insert? [MySql](MyBatis,如何獲取插入的自動(dòng)生成密鑰?[MySql])
Inserting to Oracle Nested Table in Java(在 Java 中插入 Oracle 嵌套表)
Java: How to insert CLOB into oracle database(Java:如何將 CLOB 插入 oracle 數(shù)據(jù)庫)
Why does Spring-data-jdbc not save my Car object?(為什么 Spring-data-jdbc 不保存我的 Car 對(duì)象?)
Use threading to process file chunk by chunk(使用線程逐塊處理文件)
主站蜘蛛池模板: 激情亚洲 | 夜夜草| 中文字幕高清免费日韩视频在线 | 国产精品久久久久aaaa | 久久久成人免费一区二区 | 国产1区2区3区 | 日本久久久一区二区三区 | 午夜专区 | 日韩毛片中文字幕 | 久久精品国产一区二区电影 | 亚洲欧美一区二区三区1000 | 国产精品一区二区三区久久久 | 午夜精品久久久久久久久久久久 | 狠狠涩 | 九色国产| 成人av鲁丝片一区二区小说 | 人成在线 | 国产美女一区二区 | 欧美日韩a | 精品久久久久久久久久 | 亚洲欧洲视频 | 日韩在线一区视频 | 欧美videosex性极品hd | 亚洲欧美一区二区三区国产精品 | 国产精品久久 | 国产成人av免费看 | 成人高清在线 | 一区二区三区免费 | 国产精品久久久久久一区二区三区 | 九色.com | 麻豆精品国产91久久久久久 | 亚洲成人动漫在线观看 | 操亚洲| 亚洲成a| 国精产品一区二区三区 | 亚洲精品视频免费看 | 国产一区二区三区四区 | 在线小视频 | 午夜精品一区二区三区免费视频 | 日韩91| 午夜精品久久久久久久久久久久 |