So, fairly new in here. Im trying to build a web application that simulates the act of "buying shares".
Everything ok, getting the value, working with it until i need to update the value of cash (the money the user has to spend). So, when I buy a stock, it shows the correct price, but when subtracting that value it rounds up on the SQL table.
This is the part of the code that updates the values. I can't get it to show 2 floating points.
@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)
(continues and in the end:)
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"]

Aucun commentaire:
Enregistrer un commentaire