Browse Source

Double format method matching C.

git-svn-id: https://www.prismmodelchecker.org/svn/prism/prism/trunk@1847 bbc10eb1-c90d-0410-af57-cb519fbb1720
master
Dave Parker 16 years ago
parent
commit
d244f66b44
  1. 10
      prism/src/prism/PrismUtils.java

10
prism/src/prism/PrismUtils.java

@ -180,8 +180,18 @@ public class PrismUtils
private static DecimalFormat formatterDouble2dp = new DecimalFormat("#0.00"); private static DecimalFormat formatterDouble2dp = new DecimalFormat("#0.00");
/**
* Format a double, as would be done by printf's %.12g
*/
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");
}
/** /**
* Format a double. * Format a double.
* TODO: fix me (precision ignored, re-use above code instead)
*/ */
public static String formatDouble(int precision, double d) public static String formatDouble(int precision, double d)
{ {

Loading…
Cancel
Save