久久久久久久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(使用線程逐塊處理文件)
主站蜘蛛池模板: 福利精品在线观看 | 黄色av免费| 成人精品国产 | 日韩在线观看 | 99九九视频| 久久成人精品视频 | 韩国精品一区 | 成人高清在线 | 国产成人精品一区二区三区四区 | 99re热精品视频国产免费 | 欧美日韩在线视频一区 | 久久国产综合 | 九九色综合 | 午夜精品91 | 天天色图 | 草久久久 | 五月综合激情婷婷 | 狠狠躁天天躁夜夜躁婷婷老牛影视 | 成人久草 | 在线观看免费av网 | 久久久久久91香蕉国产 | 中日韩欧美一级片 | 美国av毛片| 美女黄网站 | 色噜噜亚洲男人的天堂 | 91电影在线| 日本中文在线 | 99国产精品99久久久久久粉嫩 | 欧美中文字幕一区 | 一级毛片免费看 | 国产精品一区二区三区在线 | 天堂中文av | 黄色三级免费网站 | 91精品国产乱码久久久久久久久 | 黄色网址在线免费观看 | 亚洲综合在线一区 | a看片 | 欧洲一区二区在线 | 日本欧美国产在线观看 | 午夜影院 | a在线视频 |