From 87dd779e30db02dc7275259d543d6aa8d246ceb7 Mon Sep 17 00:00:00 2001 From: Dave Parker Date: Thu, 29 May 2014 00:27:30 +0000 Subject: [PATCH] Add Locale.UK to String.format to stop . changing to , in some places (from Jens). git-svn-id: https://www.prismmodelchecker.org/svn/prism/prism/trunk@8340 bbc10eb1-c90d-0410-af57-cb519fbb1720 --- prism/src/prism/PrismUtils.java | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/prism/src/prism/PrismUtils.java b/prism/src/prism/PrismUtils.java index 8d1b4660..d42d7e69 100644 --- a/prism/src/prism/PrismUtils.java +++ b/prism/src/prism/PrismUtils.java @@ -28,6 +28,7 @@ package prism; import java.text.DecimalFormat; import java.util.List; +import java.util.Locale; /** * Various general-purpose utility methods in Java @@ -193,8 +194,9 @@ public class PrismUtils */ public static String formatDouble(double d) { - // Note that we have to tweak this since Java do it quite like C. - return String.format("%.12g", d).replaceFirst("\\.?0+(e|$)", "$1"); + // Use UK locale to avoid . being changed to , in some countries. + // To match C's printf, we have to tweak the Java version (strip trailing .000) + return String.format(Locale.UK, "%.12g", d).replaceFirst("\\.?0+(e|$)", "$1"); } /** @@ -202,8 +204,9 @@ public class PrismUtils */ public static String formatDouble(int prec, double d) { - // Note that we have to tweak this since Java do it quite like C. - return String.format("%." + prec + "g", d).replaceFirst("\\.?0+(e|$)", "$1"); + // Use UK locale to avoid . being changed to , in some countries. + // To match C's printf, we have to tweak the Java version (strip trailing .000) + return String.format(Locale.UK, "%." + prec + "g", d).replaceFirst("\\.?0+(e|$)", "$1"); } /**