Commit 2ded879
committed
Fix directional rounding for negative numbers
ROUND_CEILING and ROUND_FLOOR produced the wrong result when formatting a
negative number. NumberPattern.apply() strips the sign before any rounding
(it formats the magnitude and renders the sign via the pattern affixes), so
the directional rounding modes rounded the magnitude and ended up rounding
toward the wrong infinity. For example, with ROUND_CEILING, format_decimal
of -100.75 returned -101 instead of -100 (ceil(-100.75) == -100).
Round using the value's original sign in both rounding sites,
_quantize_value and _format_significant, then format the magnitude. The
sign-symmetric modes (ROUND_HALF_*, ROUND_UP, ROUND_DOWN, ROUND_05UP) and
all positive-number formatting are unaffected.
Fixes #1096.1 parent baf9431 commit 2ded879
2 files changed
Lines changed: 47 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1528 | 1528 | | |
1529 | 1529 | | |
1530 | 1530 | | |
1531 | | - | |
| 1531 | + | |
1532 | 1532 | | |
1533 | 1533 | | |
1534 | 1534 | | |
1535 | 1535 | | |
1536 | 1536 | | |
1537 | 1537 | | |
1538 | 1538 | | |
1539 | | - | |
| 1539 | + | |
1540 | 1540 | | |
1541 | 1541 | | |
1542 | 1542 | | |
| |||
1550 | 1550 | | |
1551 | 1551 | | |
1552 | 1552 | | |
| 1553 | + | |
1553 | 1554 | | |
1554 | 1555 | | |
1555 | 1556 | | |
| |||
1591 | 1592 | | |
1592 | 1593 | | |
1593 | 1594 | | |
1594 | | - | |
| 1595 | + | |
1595 | 1596 | | |
1596 | 1597 | | |
1597 | | - | |
| 1598 | + | |
| 1599 | + | |
| 1600 | + | |
| 1601 | + | |
| 1602 | + | |
| 1603 | + | |
| 1604 | + | |
| 1605 | + | |
1598 | 1606 | | |
1599 | 1607 | | |
1600 | 1608 | | |
| |||
1639 | 1647 | | |
1640 | 1648 | | |
1641 | 1649 | | |
| 1650 | + | |
1642 | 1651 | | |
1643 | 1652 | | |
1644 | 1653 | | |
1645 | 1654 | | |
1646 | 1655 | | |
1647 | | - | |
| 1656 | + | |
| 1657 | + | |
| 1658 | + | |
| 1659 | + | |
| 1660 | + | |
| 1661 | + | |
1648 | 1662 | | |
1649 | 1663 | | |
1650 | 1664 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
247 | 247 | | |
248 | 248 | | |
249 | 249 | | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
250 | 278 | | |
251 | 279 | | |
252 | 280 | | |
| |||
0 commit comments