Jun 11, 2018 06:47 PM
(This post was last modified: Jun 11, 2018 06:48 PM by -Matatan-.)
I been trying to mess with the percentage in python, but every time I get more confused. when I use 0.01 that's 1% so how can I calculate 1.5%? or even 0.05% (half a percent)
based on the formula to calculate percentage which I have found on Google I made these two functions. while I can calculate 15% etc, how will I go about calculating 1.5 0.5 and so?
if there is a link or some better way to get the percentage in % and the quantity of the number I want to calculate please point me there, my brain hurts.
based on the formula to calculate percentage which I have found on Google I made these two functions. while I can calculate 15% etc, how will I go about calculating 1.5 0.5 and so?
PHP Code
<?php
def calculate(last_price, percent_buy):
z = ('{0:.2f}'.format(float(last_price) * percent_buy))
final = float(last_price) + float(z)
return final
def calculate_perc(last_price, percent_buy):
z = ('{0:.2f}'.format(float(last_price) * percent_buy))
final = float(last_price)
return final
def calculate_spend(main_balance, percent_buy):
final = '${0:.2f}'.format(float(main_balance) * percent_buy)
return final
$174.80
$22.80


