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 need to be extremely precise, you can use the BigDecimal Java class instead of floating point arithmetic. [1] X Research source
Steps
Expert Q&A
Ask a Question
200 characters left
Include your email address to get a message when this question is answered.
Submit
Advertisement
Tips
Submit a Tip
All tip submissions are carefully reviewed before being published
Name
Please provide your name and last initial
Thanks for submitting a tip for review!
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
Thanks to all authors for creating a page that has been read 65,835 times.
Advertisement