Hi,
I want to know how many number of digits are allowed after decimal point for primitive double datatype in java, without actually getting rounded off.
相关问题
- Do the Java Integer and Double objects have unnece
- How do I cast a double to an int?
- IFormatProvider scientific conversion from double
- Jquery: Prevent reloading page when pressing input
- Finding double-spaces in a string - Python
相关文章
- 关于C#中 float、double、decimal 的运算不精确的问题。
- How can I convert a OLE Automation Date value to a
- Macro or function to construct a float (double) fr
- Math.Max vs Enumerable.Max
- C# Casting to a decimal
- Set edittext using only “,0123456789” programmatic
- What are the actual ranges of floating point and d
- Print Double as Int - if not a Double value
Taken literally, the number is 0. Most decimal fractions with at least one digit after the decimal point get rounded on conversion to double. For example, the decimal fraction
0.1
is rounded to0.1000000000000000055511151231257827021181583404541015625
on conversion to double.The problem is that double is a binary floating point system, and most decimal fractions can no more be exactly represented in than 1/3 can be exactly represented as a decimal fraction with a finite number of significant digits.
As already recommended, if truly exact representation of decimal fractions is important, use
BigDecimal
.The primitive double has, for normal numbers, 53 significant bits, about 15.9 decimal digits. If very, very close is good enough, you can use double.
It depends on the number; read up on floating point representations for more information.
Use the BigDecimal class for fixed-scale arithmetic.