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

為什么從 float 轉換為 double 會改變值?

Why converting from float to double changes the value?(為什么從 float 轉換為 double 會改變值?)
本文介紹了為什么從 float 轉換為 double 會改變值?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我一直在試圖找出原因,但我找不到.有人可以幫幫我嗎?

I've been trying to find out the reason, but I couldn't. Can anybody help me?

看下面的例子.

float f = 125.32f;
System.out.println("value of f = " + f);
double d = (double) 125.32f; 
System.out.println("value of d = " + d);

這是輸出:

value of f = 125.32
value of d = 125.31999969482422

推薦答案

float 的值在轉換為 double 時不會改變.顯示的數字有所不同,因為需要更多數字來區分 double 值與其相鄰值,即 Java 文檔要求.那是 toString 的文檔,從 println 的文檔中引用(通過幾個鏈接).

The value of a float does not change when converted to a double. There is a difference in the displayed numerals because more digits are required to distinguish a double value from its neighbors, which is required by the Java documentation. That is the documentation for toString, which is referred (through several links) from the documentation for println.

125.32f 的確切值是 125.31999969482421875.兩個相鄰的 float 值是 125.3199920654296875 和 125.32000732421875.觀察到 125.32 比任何一個鄰居都更接近 125.31999969482421875.因此,通過顯示125.32",Java 顯示了足夠的數字,以便從十進制數字轉換回 float 再現了傳遞給 println<的 float 的值/代碼>.

The exact value for 125.32f is 125.31999969482421875. The two neighboring float values are 125.3199920654296875 and 125.32000732421875. Observe that 125.32 is closer to 125.31999969482421875 than to either of the neighbors. Therefore, by displaying "125.32", Java has displayed enough digits so that conversion back from the decimal numeral to float reproduces the value of the float passed to println.

在兩個相鄰<代碼>雙的125.3199996948242的 1875 是125.3199996948242的 045391452847979962825775146484375 并125.3199996948242的 329608547152020037174224853515625 即可.值結果觀察到 125.32 更接近后一個鄰居而不是原始值 (125.31999969482421875).因此,打印125.32"不包含足夠的數字來區分原始值.Java 必須打印更多的數字,以確保從顯示的數字轉換回 double 再現傳遞給 printlndouble 的值.

The two neighboring double values of 125.31999969482421875 are 125.3199996948242045391452847979962825775146484375 and 125.3199996948242329608547152020037174224853515625.
Observe that 125.32 is closer to the latter neighbor than to the original value (125.31999969482421875). Therefore, printing "125.32" does not contain enough digits to distinguish the original value. Java must print more digits in order to ensure that a conversion from the displayed numeral back to double reproduces the value of the double passed to println.

這篇關于為什么從 float 轉換為 double 會改變值?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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(使用線程逐塊處理文件)
主站蜘蛛池模板: 国产精品久久久久久久久久久久久久 | 啪啪免费 | 欧美xxxx网站 | 国产精品久久久久久久久久久久久久 | 国产一区二区 | 亚洲国产91| 99热这里都是精品 | 精品啪啪| 成人在线精品视频 | 中文字幕在线视频免费视频 | 久久久无码精品亚洲日韩按摩 | 欧美日韩亚洲国产综合 | 91精品国产一区二区三区蜜臀 | 久久亚洲一区二区三 | 久久久久成人精品 | а天堂中文最新一区二区三区 | 婷婷综合激情 | 欧洲亚洲精品久久久久 | 91精品国产91久久久久游泳池 | 亚洲精品视频一区 | 欧美性受xxxx | 一区二区三区高清在线观看 | 一级毛片免费完整视频 | 亚洲午夜精品久久久久久app | 精品av| 男女视频在线免费观看 | zzzwww在线看片免费 | 国产ts人妖另类 | 青青草华人在线视频 | 久久精品成人热国产成 | 久久一区二区三区四区五区 | 日本在线免费看最新的电影 | 91视频网 | 日韩精品成人在线 | 国产成人免费视频 | 中文字幕在线观看视频一区 | 免费一区 | 一级毛片大全免费播放 | 日本精品视频一区二区 | 亚洲成人黄色 | 国产精品夜夜夜一区二区三区尤 |