Permalink
Browse files

Format CSS percentage with US locale.

  • Loading branch information...
sk89q committed Jun 14, 2013
1 parent c052f22 commit 6c93fd8741a3e26b64eec5804f4d52ca28c900f8
Showing with 14 additions and 2 deletions.
  1. +14 −2 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 @@ private void writeHtml(StringBuilder builder, McpMapping mapping, long totalTime
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 String toString() {
return builder.toString();
}
protected static String formatCssPct(double pct) {
return cssDec.format(pct);
}
protected static String escapeHtml(String str) {
return str.replace("&", "&amp;").replace("<", "&lt;").replace(">", "&gt;");
}

0 comments on commit 6c93fd8

Please sign in to comment.