On Feb 25, 2:44 am, [EMAIL PROTECTED] wrote: > Hi I'm very much a beginner with Python. > I want to write a function to convert celcius to fahrenheit like this > one: > > def celciusToFahrenheit(tc): > tf = (9/5)*tc+32 > return tf > > I want the answer correct to one decimal place, so > celciusToFahrenheit(12) would return 53.6. > > Of course the function above returns 53.600000000000001. > > How do I format it correctly?
That is the normal behavior for binary (radix-2) numbers. Just like it is impossible write 1/3 exactly as a decimal (radix-10) number, 536/10 cannot be written exactly as a binary number. If you really need decimal numbers, use the Decimal class. See http://docs.python.org/tut/node16.html. casevh -- http://mail.python.org/mailman/listinfo/python-list