更新烧瓶中的 SQL 查询不适用于浮点/小数点

问题描述

所以,这里相当新。我正在尝试构建一个模拟“购买股票”行为的网络应用程序。

一切正常,获取价值,使用它直到我需要更新现金的价值(用户必须花费的钱)。因此,当我购买股票时,它会显示正确的价格,但是当减去该值时,它会在 SQL 表中四舍五入。

this is the picture of the summary ive built

这是更新值的代码部分。我无法让它显示 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 (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...