This article was written by Anne Schmidt and by How.com.vn staff writer, Nicole Levine, MFA. Anne Schmidt is a Chemistry Instructor in Wisconsin. Anne has been teaching high school chemistry for over 20 years and is passionate about providing accessible and educational chemistry content. She has over 9,000 subscribers to her educational chemistry YouTube channel. She has presented at the American Association of Chemistry Teachers (AATC) and was an Adjunct General Chemistry Instructor at Northeast Wisconsin Technical College. Anne was published in the Journal of Chemical Education as a Co-Author, has an article in ChemEdX, and has presented twice and was published with the AACT. Anne has a BS in Chemistry from the University of Wisconsin, Oshkosh, and an MA in Secondary Education and Teaching from Viterbo University.
This article has been fact-checked, ensuring the accuracy of any cited facts and confirming the authority of its sources.
This article has been viewed 57,665 times.
This How.com.vn article will show you three ways to do decimal numbers in Java. If you want to divide two integers (non-decimal) and get a non-rounded answer, cast one of the operands to a double. To divide two decimal numbers (or an integer by a decimal or vice-versa), you can use simple double division to ensure a decimal result. When working with larger numbers or numbers that needs to be extremely precise, you can use the BigDecimal Java class instead of floating point arithmetic.[1]
Steps
Expert Q&A
Tips
References
- ↑ https://www.geeksforgeeks.org/bigdecimal-class-java/
- ↑ https://mathbits.com/MathBits/Java/DataBasics/Mathoperators.htm
- ↑ https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html
- ↑ https://docs.oracle.com/javase/7/docs/api/java/math/BigDecimal.html
- ↑ https://docs.oracle.com/javase/7/docs/api/java/math/RoundingMode.html
About This Article
Did this article help you?
⚠️ Disclaimer:
Content from Wiki How English language website. Text is available under the Creative Commons Attribution-Share Alike License; additional terms may apply.
Wiki How does not encourage the violation of any laws, and cannot be responsible for any violations of such laws, should you link to this domain, or use, reproduce, or republish the information contained herein.
- - A few of these subjects are frequently censored by educational, governmental, corporate, parental and other filtering schemes.
- - Some articles may contain names, images, artworks or descriptions of events that some cultures restrict access to
- - Please note: Wiki How does not give you opinion about the law, or advice about medical. If you need specific advice (for example, medical, legal, financial or risk management), please seek a professional who is licensed or knowledgeable in that area.
- - Readers should not judge the importance of topics based on their coverage on Wiki How, nor think a topic is important just because it is the subject of a Wiki article.