简体   繁体   中英

How to expand a number in scientific notation in Jinja2?

So, let's say I have a long floating-point number stored in my database (ex: 0.00000003), but Jinja2 displays this number in scientific notation, which is bit awkward for what I'm expecting with my flask app. Is there any way to directly expand numbers in scientific notations in Jinja2, as we do in python using format:

number = 3e-08     
format(number, '.8f')

You are already giving the answer yourself. Use format on the number before you pass it to the template. Or use format in the template.

from flask import Flask, render_template_string

app = Flask(__name__)

number=3e-08

with app.app_context():
    render_template_string('{{s}}', s=format(number, '.8f'))

    render_template_string('{{ "%.8f"|format(d)}}', d=number)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM