Re: Getting fractional part from a float without using string operations

2008-11-20 Thread James Harris
On 20 Nov, 06:01, srinivasan srinivas [EMAIL PROTECTED] wrote: Yes it works for most of the cases. But it doesn't for the following case: str(abs(int(1234567.89)-1234567.89)) '0.88999898' Well, that is 0.89 or about as near to it as the calculation can represent. Like other numbers

Getting fractional part from a float without using string operations

2008-11-19 Thread srinivasan srinivas
Thanks, Srini Add more friends to your messenger and enjoy! Go to http://messenger.yahoo.com/invite/ -- http://mail.python.org/mailman/listinfo/python-list

Re: Getting fractional part from a float without using string operations

2008-11-19 Thread Jeremiah Dodds
On Wed, Nov 19, 2008 at 8:35 AM, srinivasan srinivas [EMAIL PROTECTED] wrote: Thanks, Srini Add more friends to your messenger and enjoy! Go to http://messenger.yahoo.com/invite/ -- http://mail.python.org/mailman/listinfo/python-list x = 2.99340584 y = abs(int(x) - x) y 0.99340584

Re: Getting fractional part from a float without using string operations

2008-11-19 Thread John Machin
On Nov 20, 12:35 am, srinivasan srinivas [EMAIL PROTECTED] wrote: null | import math | num = 123.4567 | math.modf(num) | (0.456699789, 123.0) -- http://mail.python.org/mailman/listinfo/python-list

Re: Getting fractional part from a float without using string operations

2008-11-19 Thread srinivasan srinivas
, 2008 7:14:17 PM Subject: Re: Getting fractional part from a float without using string operations On Wed, Nov 19, 2008 at 8:35 AM, srinivasan srinivas [EMAIL PROTECTED] wrote: Thanks, Srini      Add more friends to your messenger and enjoy! Go to http://messenger.yahoo.com/invite/ -- http

Re: Getting fractional part from a float without using string operations

2008-11-19 Thread MRAB
On Nov 19, 1:44 pm, John Machin [EMAIL PROTECTED] wrote: On Nov 20, 12:35 am, srinivasan srinivas [EMAIL PROTECTED] wrote: null | import math | num = 123.4567 | math.modf(num) | (0.456699789, 123.0) def frac(n): return n - int(n) --

Re: Getting fractional part from a float without using string operations

2008-11-19 Thread Tino Wildenhain
srinivasan srinivas wrote: Yes. But it didn't give only the expected decimals. For ex: a = 1.23 abs(int(a) -a) 0.22998 I would like to get the result '0.23' only. well, thats what get stored internally - there is no way around it if you are using floating point numbers:

Re: Getting fractional part from a float without using string operations

2008-11-19 Thread Blind Anagram
MRAB [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] On Nov 19, 1:44 pm, John Machin [EMAIL PROTECTED] wrote: On Nov 20, 12:35 am, srinivasan srinivas [EMAIL PROTECTED] wrote: null | import math | num = 123.4567 | math.modf(num) | (0.456699789, 123.0) def frac(n):

Re: Getting fractional part from a float without using string operations

2008-11-19 Thread John Machin
On Nov 20, 3:38 am, Blind Anagram [EMAIL PROTECTED] wrote: MRAB [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] On Nov 19, 1:44 pm, John Machin [EMAIL PROTECTED] wrote: On Nov 20, 12:35 am, srinivasan srinivas [EMAIL PROTECTED] wrote: null | import math | num = 123.4567

Re: Getting fractional part from a float without using string operations

2008-11-19 Thread srinivasan srinivas
]; python-list@python.org Sent: Wednesday, 19 November, 2008 7:33:46 PM Subject: Re: Getting fractional part from a float without using string operations srinivasan srinivas wrote: Yes. But it didn't give only the expected decimals. For ex:   a = 1.23   abs(int(a) -a) 0.22998   I

Re: Getting fractional part from a float without using string operations

2008-11-19 Thread Chris Rebert
]; python-list@python.org Sent: Wednesday, 19 November, 2008 7:33:46 PM Subject: Re: Getting fractional part from a float without using string operations srinivasan srinivas wrote: Yes. But it didn't give only the expected decimals. For ex: a = 1.23 abs(int(a) -a) 0.22998