[Tutor] How to correct decimal addition.

Norman Khine norman at khine.net
Fri Jan 24 23:44:18 CET 2014


maybe this would be of help

https://stackoverflow.com/questions/455612/python-limiting-floats-to-two-decimal-points


On Fri, Jan 24, 2014 at 5:57 PM, Leon S <imtherealleon at gmail.com> wrote:

> Here is what I'm trying to do, accept a price of gas, but I want to add
> the .009 to the price, so that people do not have to type the full amount.
>  Example, 3.49 /gallon would return 3.499 /gallon.
>
> This is what I have tried and the results of it.
>
> def gas_price(price):
>    price == raw_input("What is the price of gas?")  return price + .09   3.49=> 3.4899999999999998
>
>
> It reduces the number and then adds many decimal points after.
>
>
> Thanks for any help, I am sure this is an easy one for someone.
>
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>
>


-- 
%>>> "".join( [ {'*':'@','^':'.'}.get(c,None) or chr(97+(ord(c)-83)%26) for
c in ",adym,*)&uzq^zqf" ] )
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20140124/1d2e3c87/attachment.html>


More information about the Tutor mailing list