def currency(number, isPercent): #trunkates the 'number' variable to the 100's place base = int(number) remain = number - base decStep = remain*100 decimal = int(decStep) decimal = float(decimal) decimal = decimal/100 money = base + decimal money = str(money) #conditional that adds an additonal '0' to the number if the decimal # only goes to the 10's place zeroChk = remain *10 if zeroChk == int(zeroChk): money = money + "0" #conditional that will put in a dollar sign '$' if requested by making # isPercent equal to zero, and insert a '%' if isPercent equals 1 if isPercent == 0: #money = str(money) money = "$" + money elif isPercent == 1: #money = str(money) money = money + "%" return money
as you may have noticed the 'isPercent' variable doesn't really have to do with currency, but the way i was using it, it made the function a little more useful. if 'isPercent' is equal to 1 then instead of '$' before the number, it prints a '%' after the number, and if 'isPercent' is equal to 0 then the opposite is true, and if it is neither it doesn't print a '$' or '%'
I hope this helps =D
oh and btw, if there is a currency function built into python, what is it?