This article was written by Anne Schmidt and by wikiHow 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,452 times.
This wikiHow 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