1Z0-811 Primitives, Strings and Operators Practice Question
A scientific application performs calculations with double precision. A specific formula divides two double values: result = a / b; where a and b are calculated from sensor readings. The result is expected to be at most 10 decimal digits of precision. However, the output often shows small rounding errors, e.g., 0.1 + 0.2 = 0.30000000000000004. The application must meet strict accuracy requirements and cannot tolerate these small errors. Which strategy should be used to achieve exact decimal representation?
Answer choices
Why each option matters
Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.
Correct answer & explanation
✓
Use BigDecimal with an appropriate scale and rounding mode.
Floating-point arithmetic (double) inherently has rounding errors due to binary representation, as shown in the example 0.1 + 0.2 = 0.30000000000000004. BigDecimal provides arbitrary-precision decimal arithmetic and allows specifying scale and rounding modes, making it ideal for exact decimal calculations meeting the 10-digit precision requirement. Therefore, Option A (BigDecimal) is the correct approach. Option B (Math.round) rounds to an integer, losing fractional precision. Option C (float) uses less precision than double, worsening errors. Option D (casting to int after scaling) truncates and risks loss of information.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✓
Use BigDecimal with an appropriate scale and rounding mode.
Why this is correct
BigDecimal represents decimal numbers exactly and allows controlling precision and rounding, eliminating floating-point rounding errors.
- ✗
Apply Math.round() to the result to reduce decimal places.
Why it's wrong here
Math.round() returns a long (or int) by rounding to the nearest integer, losing all fractional precision.
- ✗
Use the float data type instead of double to reduce memory usage.
Why it's wrong here
float has even lower precision than double and will still exhibit rounding errors, possibly more severe.
- ✗
Cast the result to int after multiplying by a power of 10.
Why it's wrong here
This truncates the fractional part, losing precision, and does not solve the inherent rounding error.
Go deeper
Related to this question
About these practice questions
This 1Z0-811 question is part of Courseiva's 481-question bank — original exam-style content with full explanations and wrong-answer analysis, never real exam questions or exam dumps. Learn why practice questions differ from exam dumps →
JA
Written by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
This 1Z0-811 practice question is part of Courseiva's free Oracle certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the 1Z0-811 exam.