diff --git a/prism/src/param/BigRational.java b/prism/src/param/BigRational.java index 459d32d1..daa0e58f 100644 --- a/prism/src/param/BigRational.java +++ b/prism/src/param/BigRational.java @@ -824,6 +824,22 @@ public final class BigRational implements Comparable throw new PrismLangException("Conversion from BigRational to Boolean not possible, invalid value: " + this); } + /** + * Return an approximate String representation (via conversion to double). + * If the conversion is imprecise, the result string is prefixed by '~'. + */ + public String toApproximateString() + { + String result = Double.toString(doubleValue()); + if (new BigRational(result).equals(this)) { + // round-trip did not lose precision + return result; + } + // only approximate + return "~" + result; + + } + /** * Returns the int representation of this value, * if this value is an integer and if the integer can