diff options
author | Albert Pham <the.sk89q@gmail.com> | 2013-06-14 15:29:44 -0700 |
---|---|---|
committer | Albert Pham <the.sk89q@gmail.com> | 2013-06-14 15:29:44 -0700 |
commit | 6c93fd8741a3e26b64eec5804f4d52ca28c900f8 (patch) | |
tree | 175ac7642343f519aa747e428f2e1327810ae24c /src | |
parent | c052f22d913f1ef328ce96f0e42bcfd152bbcddc (diff) | |
download | spark-6c93fd8741a3e26b64eec5804f4d52ca28c900f8.tar.gz spark-6c93fd8741a3e26b64eec5804f4d52ca28c900f8.tar.bz2 spark-6c93fd8741a3e26b64eec5804f4d52ca28c900f8.zip |
Format CSS percentage with US locale.
Diffstat (limited to 'src')
-rw-r--r-- | src/main/java/com/sk89q/warmroast/StackNode.java | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/src/main/java/com/sk89q/warmroast/StackNode.java b/src/main/java/com/sk89q/warmroast/StackNode.java index 216ca5f..71a4f54 100644 --- a/src/main/java/com/sk89q/warmroast/StackNode.java +++ b/src/main/java/com/sk89q/warmroast/StackNode.java @@ -18,18 +18,26 @@ package com.sk89q.warmroast; +import java.text.NumberFormat; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.HashMap; import java.util.List; +import java.util.Locale; import java.util.Map; public class StackNode implements Comparable<StackNode> { + private static final NumberFormat cssDec = NumberFormat.getPercentInstance(Locale.US); private final String name; private final Map<String, StackNode> children = new HashMap<>(); private long totalTime; + + static { + cssDec.setGroupingUsed(false); + cssDec.setMaximumFractionDigits(2); + } public StackNode(String name) { this.name = name; @@ -111,8 +119,8 @@ public class StackNode implements Comparable<StackNode> { builder.append("</span>"); builder.append("<span class=\"bar\">"); builder.append("<span class=\"bar-inner\" style=\"width:") - .append(String.format("%.2f", getTotalTime() / (double) totalTime * 100)) - .append("%\">"); + .append(formatCssPct(getTotalTime() / (double) totalTime)) + .append("\">"); builder.append("</span>"); builder.append("</span>"); builder.append("</div>"); @@ -155,6 +163,10 @@ public class StackNode implements Comparable<StackNode> { return builder.toString(); } + protected static String formatCssPct(double pct) { + return cssDec.format(pct); + } + protected static String escapeHtml(String str) { return str.replace("&", "&").replace("<", "<").replace(">", ">"); } |