Is there a datatype in Java that stores a decimal number more precisely than a double?
Is there a datatype in Java that stores a decimal number more precisely than
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Yes, use java.math.BigDecimal class. It can represent numbers with great precision.
If you just need huge integers, you can use java.math.BigInteger instead.
They both extend java.math.Number.
You can even use your existing doubles if you need:
And you can get BigDecimal values out of databases with JDBC:
Unfortunately, since Java does not support operator overloading, you can’t use regular symbols for common mathematical operations like you would in C# and the
decimaltype.You will need to write code like this: