Author: Daniel Roberts <ademan...@gmail.com> Branch: Changeset: r45330:53da334735e9 Date: 2011-07-04 00:39 -0700 http://bitbucket.org/pypy/pypy/changeset/53da334735e9/
Log: Support different precision float formatting. Accompanying test isn't very good, but there was none before. diff --git a/pypy/translator/jvm/src/pypy/PyPy.java b/pypy/translator/jvm/src/pypy/PyPy.java --- a/pypy/translator/jvm/src/pypy/PyPy.java +++ b/pypy/translator/jvm/src/pypy/PyPy.java @@ -969,7 +969,10 @@ // XXX: this is really a quick hack to make things work. // it should disappear, because this function is not // supported by ootypesystem. - return Double.toString(d); // XXX: we are ignoring "format" + DecimalFormat format = new DecimalFormat("0.###"); + format.setMinimumFractionDigits(precision); + format.setMaximumFractionDigits(precision); + return format.format(d); } // ---------------------------------------------------------------------- diff --git a/pypy/translator/jvm/test/test_float.py b/pypy/translator/jvm/test/test_float.py --- a/pypy/translator/jvm/test/test_float.py +++ b/pypy/translator/jvm/test/test_float.py @@ -22,3 +22,14 @@ def test_r_singlefloat(self): py.test.skip("not implemented: single-precision floats") + + def test_format_float(self): + from pypy.rlib.rfloat import _formatd + def fn(precision): + return _formatd(10.01, 'd', precision, 0) + + res = self.interpret(fn, [2]) + assert res == "10.01" + + res = self.interpret(fn, [1]) + assert res == "10.0" _______________________________________________ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit