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

Java:為什么在現(xiàn)實(shí)世界中我們應(yīng)該使用 BigDecimal

Java:Why should we use BigDecimal instead of Double in the real world?(Java:為什么在現(xiàn)實(shí)世界中我們應(yīng)該使用 BigDecimal 而不是 Double?)
本文介紹了Java:為什么在現(xiàn)實(shí)世界中我們應(yīng)該使用 BigDecimal 而不是 Double?的處理方法,對(duì)大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

在處理現(xiàn)實(shí)世界的貨幣值時(shí),建議我使用 BigDecimal 而不是 Double.但我沒有得到令人信服的解釋,除了通常這樣做".

When dealing with real world monetary values, I am advised to use BigDecimal instead of Double.But I have not got a convincing explanation except, "It is normally done that way".

你能解釋一下這個(gè)問題嗎?

Can you please throw light on this question?

推薦答案

這稱為精度損失,在處理非常大或非常小的數(shù)字時(shí)非常明顯.帶基數(shù)的十進(jìn)制數(shù)的二進(jìn)制表示在許多情況下是近似值而不是絕對(duì)值.要了解為什么您需要閱讀二進(jìn)制中的浮點(diǎn)數(shù)表示.這是一個(gè)鏈接:http://en.wikipedia.org/wiki/IEEE_754-2008.這是一個(gè)快速演示:
在精度=10 的 bc(任意精度計(jì)算器語言)中:

It's called loss of precision and is very noticeable when working with either very big numbers or very small numbers. The binary representation of decimal numbers with a radix is in many cases an approximation and not an absolute value. To understand why you need to read up on floating number representation in binary. Here is a link: http://en.wikipedia.org/wiki/IEEE_754-2008. Here is a quick demonstration:
in bc (An arbitrary precision calculator language) with precision=10:

(1/3+1/12+1/8+1/15) = 0.6083333332
(1/3+1/12+1/8) = 0.541666666666666
(1/3+1/12) = 0.416666666666666

(1/3+1/12+1/8+1/15) = 0.6083333332
(1/3+1/12+1/8) = 0.541666666666666
(1/3+1/12) = 0.416666666666666

Java 雙重:
0.6083333333333333
0.5416666666666666
0.41666666666666663

Java double:
0.6083333333333333
0.5416666666666666
0.41666666666666663

Java 浮點(diǎn)數(shù):

Java float:

0.60833335
0.5416667
0.4166667

0.60833335
0.5416667
0.4166667

這篇關(guān)于Java:為什么在現(xiàn)實(shí)世界中我們應(yīng)該使用 BigDecimal 而不是 Double?的文章就介紹到這了,希望我們推薦的答案對(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(使用線程逐塊處理文件)
主站蜘蛛池模板: 岛国av一区二区三区 | 国产视频三区 | 一区观看| 成人二区 | 久久国产福利 | 国产夜恋视频在线观看 | 中文一区二区 | 91中文字幕在线观看 | 国产免费va | 久草欧美 | 91五月天| 操久久| 一区二区三区在线观看视频 | 在线观看视频一区 | 激情黄色在线观看 | 日韩欧美亚洲 | 精精国产xxxx视频在线野外 | 999精品视频 | 干一干操一操 | 97国产一区二区精品久久呦 | 成人乱人乱一区二区三区软件 | 男女一区二区三区 | 久久国产精品偷 | 欧美黑人国产人伦爽爽爽 | 国产在线观看一区二区三区 | 午夜羞羞 | 日韩精品在线视频免费观看 | 美女亚洲一区 | 亚洲精品亚洲人成人网 | 成人免费视频 | 91高清视频在线观看 | 中文字幕加勒比 | 日本中文字幕在线视频 | 国产激情免费视频 | 91网站在线看 | av首页在线 | 亚洲精品视频在线播放 | 国产999精品久久久 精品三级在线观看 | www.日韩 | 天天操操 | 精品免费国产一区二区三区四区 |