From 68a5f05bb51861a33c737f66b3fd08b4bda4a391 Mon Sep 17 00:00:00 2001 From: Graham Dixon Date: Fri, 21 May 2021 20:10:55 +0100 Subject: [PATCH] Uses numpy to fix float formatting/rounding --- app/quadraticlands/templatetags/token_format.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/quadraticlands/templatetags/token_format.py b/app/quadraticlands/templatetags/token_format.py index 348aa438245..436a11c0c62 100644 --- a/app/quadraticlands/templatetags/token_format.py +++ b/app/quadraticlands/templatetags/token_format.py @@ -1,7 +1,9 @@ from django import template +import numpy as np + register = template.Library() @register.filter def token_format(value): - return "%.2f" % float(value) if float(value) > 1 else str('{:.18f}'.format(value)).rstrip('0') + return "%.2f" % value if value >= 1 else np.format_float_positional(value)