Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the rounding issue for numeric type formatting #650

Open
wants to merge 1 commit into
base: trunk
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -823,6 +823,14 @@ private Object scaleInput(Object obj) {
@Override
public StringBuffer format(Object obj, StringBuffer toAppendTo, FieldPosition pos) {
obj = scaleInput(obj);
// Resolve the current issue with the DecimalFormat class when the incoming obj is of type Double or Float
// For example, if a Double type value of 1.005 is passed in, and the corresponding cell in Excel is of numeric type
// and set to keep two decimal places
// Formatting the Double value 1.005 will be problematic; it will be formatted as 1.00, which is inconsistent with
// the behavior of Excel and does not perform rounding correctly
if (obj instanceof Double || obj instanceof Float) {
return df.format(new BigDecimal(obj.toString()), toAppendTo, pos);
}
return df.format(obj, toAppendTo, pos);
}

Expand Down