[Tutor] eval and floating point
Bill Campbell
bill at celestial.net
Thu Jan 15 05:12:31 CET 2009
On Wed, Jan 14, 2009, jadrifter wrote:
>On Thu, 2009-01-15 at 12:19 +1000, Mr Gerard Kelly wrote:
>> Thanks very much
>>
>> I've noticed that the eval() function gives an integer, so eval("3/2")
>> gives back 1. float(eval("3/2")) doesn't seem to work, any way to get a
>> floating point number back with eval()?
>>
>> I know you can just do ("3./2."), but is there any way to do it with
>> just ("3/2")?
>
>That's not the eval function returning that integer so much as it is
>Python itself. You might try:
>eval ("1.0 * 3/2")
Make either the numerator or denominator floating point.
eval ('3.0/2')
Python does the Right Thing(tm) when dividing two integers,
returning an integer result.
Bill
--
INTERNET: bill at celestial.com Bill Campbell; Celestial Software LLC
URL: http://www.celestial.com/ PO Box 820; 6641 E. Mercer Way
Voice: (206) 236-1676 Mercer Island, WA 98040-0820
Fax: (206) 232-9186
The essence of all slavery consists in taking the produce of another's
labor by force. It is immaterial whether this force be founded on ownership
of the slave or ownership of the money that he must get to live on.
Leo Tolstoy 1891
More information about the Tutor
mailing list