Issue #228 wontfix

Workaround for Python Issue 16609

Freddie Witherden
created an issue

Python 2.7 has an limitation whereby str(afloat) causes unnecessary truncation (Issue 16609: This causes:

print Template('${x}').render(x=1.0/3.0)

which is only good to some 12 decimal places. It would be good if Mako could special-case the handling of floating point numbers to call repr as opposed to str. This issue is a particularly troublesome in the scientific Python community where Mako has found a place for generating source code (and hence the precision of substituted constants is important).

Comments (3)

  1. Mike Bayer repo owner

    make your own default filter which does this, if you want it automatic in all cases. Mako cannot provide an expensive filter like this by default.

    In real world apps I always use explicit formatters in any case:

        from myapp import formatters
    ${my_fp_value | n,formatters.float}
  2. Cody Taylor

    I vote to close this issue. Python marked this as not an issue, so should mako. Secondly, even this report is entitled "work around", which shouldn't make it into library code at all costs. Work arounds belong in documentation or on stackoverflow.

  3. Log in to comment