diff --git a/app/__init__.py b/app/__init__.py index 1766761..31534e7 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -62,4 +62,15 @@ def create_app(config_name=None): def percent_filter(value): return format_percent(value) + @app.template_filter('shares') + def shares_filter(value): + """Format share quantity — strips trailing zeros, keeps up to 8 decimal places.""" + try: + f = float(value) + except (TypeError, ValueError): + return '0' + # Format to 8 decimal places then strip trailing zeros + s = '{:.8f}'.format(f).rstrip('0').rstrip('.') + return s if s else '0' + return app diff --git a/app/templates/investments/detail.html b/app/templates/investments/detail.html index 4817a95..b1a2b81 100644 --- a/app/templates/investments/detail.html +++ b/app/templates/investments/detail.html @@ -31,7 +31,7 @@
Shares
-
{{ "%.6f"|format(inv.shares|float)|replace('000000','').rstrip('0').rstrip('.') }}
+
{{ inv.shares | shares }}
Avg Cost
diff --git a/app/templates/investments/index.html b/app/templates/investments/index.html index 3791948..19713d3 100644 --- a/app/templates/investments/index.html +++ b/app/templates/investments/index.html @@ -135,7 +135,7 @@
- {{ "%.4f"|format(inv.shares|float) | replace('.0000','') }} + {{ inv.shares | shares }} {% if inv.current_price %}