Browse Source

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
master
Dave Parker 12 years ago
parent
commit
87dd779e30
  1. 11
      prism/src/prism/PrismUtils.java

11
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");
}
/**

Loading…
Cancel
Save