如何解决更新烧瓶中的 SQL 查询不适用于浮点/小数点
所以,这里相当新。我正在尝试构建一个模拟“购买股票”行为的网络应用程序。
一切正常,获取价值,使用它直到我需要更新现金的价值(用户必须花费的钱)。因此,当我购买股票时,它会显示正确的价格,但是当减去该值时,它会在 SQL 表中四舍五入。
这是更新值的代码部分。我无法让它显示 2 个浮点数。
@app.route("/")
@login_required
def index():
"""Show portfolio of stocks"""
# Get the user ID
user_id = session.get('user_id',None)
# Get the symbol. Query first on stocks SQL
dictionary = db.execute("SELECT symbol,SUM(shares),company FROM buy_stocks WHERE userid=(:userid) GROUP BY company",userid = user_id)
# Get the number to iterate on the HTML template
iterate = len(dictionary)
symbol = [None] * len(dictionary)
(继续到最后:)
for i in range(len(dictionary)):
value = int( 100 * price[i] * shares[i] )
value_temp = value / 100
total[i] = value_temp
# Cash still avaiable for more transactions. Sum the total and subtract to the money the user still has
cash_query = db.execute("SELECT cash FROM users WHERE id=(:userid)",userid = user_id)
cash = cash_query[0]["cash"]
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。