diff options
author | Evgeny Mandrikov <Godin@users.noreply.github.com> | 2016-09-26 20:20:07 +0200 |
---|---|---|
committer | Marc R. Hoffmann <hoffmann@mountainminds.com> | 2016-09-26 20:20:07 +0200 |
commit | 9b1c6f5a0ead14e253e9809cce37edf7ea8bcafb (patch) | |
tree | 9b61130d42ebbd1e778c1edb4fcc3d7dada892e1 /org.jacoco.report/src | |
parent | 616b5fbe1de4b6aa67452635d3faaa1f4920a608 (diff) | |
download | jacoco-9b1c6f5a0ead14e253e9809cce37edf7ea8bcafb.tar.gz |
Use RoundingMode#FLOOR for percentages in HTML report (#452)
Diffstat (limited to 'org.jacoco.report/src')
-rw-r--r-- | org.jacoco.report/src/org/jacoco/report/internal/html/table/PercentageColumn.java | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/org.jacoco.report/src/org/jacoco/report/internal/html/table/PercentageColumn.java b/org.jacoco.report/src/org/jacoco/report/internal/html/table/PercentageColumn.java index 3f9a21a8..45105fdb 100644 --- a/org.jacoco.report/src/org/jacoco/report/internal/html/table/PercentageColumn.java +++ b/org.jacoco.report/src/org/jacoco/report/internal/html/table/PercentageColumn.java @@ -12,7 +12,8 @@ package org.jacoco.report.internal.html.table; import java.io.IOException; -import java.text.DecimalFormat; +import java.math.BigDecimal; +import java.math.RoundingMode; import java.text.NumberFormat; import java.util.Comparator; import java.util.List; @@ -50,7 +51,7 @@ public class PercentageColumn implements IColumnRenderer { */ public PercentageColumn(final CounterEntity entity, final Locale locale) { this.entity = entity; - this.percentageFormat = DecimalFormat.getPercentInstance(locale); + this.percentageFormat = NumberFormat.getPercentInstance(locale); comparator = new TableItemComparator( CounterComparator.MISSEDRATIO.on(entity)); } @@ -79,10 +80,21 @@ public class PercentageColumn implements IColumnRenderer { if (total == 0) { td.text("n/a"); } else { - td.text(percentageFormat.format(counter.getCoveredRatio())); + td.text(format(counter.getCoveredRatio())); } } + /** + * Ratio 199/(1+199)=0.995 must be displayed as "99%", not as "100%". + * Unfortunately {@link NumberFormat} uses {@link RoundingMode#HALF_EVEN} by + * default and ability to change available only starting from JDK 6, so + * perform rounding using {@link RoundingMode#FLOOR} before formatting. + */ + private String format(double ratio) { + return percentageFormat.format( + BigDecimal.valueOf(ratio).setScale(2, RoundingMode.FLOOR)); + } + public Comparator<ITableItem> getComparator() { return comparator; } |