mirror of
https://github.com/apache/poi.git
synced 2026-02-27 20:40:08 +08:00
[github-321] Fix issue with rounding in DataFormatter. First try broke a test.
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1899686 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
4682903e6a
commit
be2a929f44
@ -950,7 +950,14 @@ public class DataFormatter {
|
||||
if (numberFormat == null) {
|
||||
return Double.toString(d);
|
||||
}
|
||||
String formatted = numberFormat.format(new BigDecimal(Double.toString(d)));
|
||||
String formatted;
|
||||
try {
|
||||
//see https://github.com/apache/poi/pull/321 -- but this sometimes fails as Double.toString
|
||||
//can produce strings that can't be parsed by BigDecimal
|
||||
formatted = numberFormat.format(new BigDecimal(Double.toString(d)));
|
||||
} catch (NumberFormatException nfe) {
|
||||
formatted = numberFormat.format(d);
|
||||
}
|
||||
return formatted.replaceFirst("E(\\d)", "E+$1"); // to match Excel's E-notation
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user