From 6c93fd8741a3e26b64eec5804f4d52ca28c900f8 Mon Sep 17 00:00:00 2001 From: Albert Pham Date: Fri, 14 Jun 2013 15:29:44 -0700 Subject: Format CSS percentage with US locale. --- src/main/java/com/sk89q/warmroast/StackNode.java | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'src/main/java/com/sk89q/warmroast/StackNode.java') 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 { + private static final NumberFormat cssDec = NumberFormat.getPercentInstance(Locale.US); private final String name; private final Map 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 { builder.append(""); builder.append(""); builder.append(""); + .append(formatCssPct(getTotalTime() / (double) totalTime)) + .append("\">"); builder.append(""); builder.append(""); builder.append(""); @@ -155,6 +163,10 @@ public class StackNode implements Comparable { return builder.toString(); } + protected static String formatCssPct(double pct) { + return cssDec.format(pct); + } + protected static String escapeHtml(String str) { return str.replace("&", "&").replace("<", "<").replace(">", ">"); } -- cgit