By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,171 Members | 776 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,171 IT Pros & Developers. It's quick & easy.

Getting fractional part from a float without using string operations

P: n/a
Thanks,
Srini
Add more friends to your messenger and enjoy!Go to http://messenger.yahoo.com/invite/
Nov 19 '08 #1
Share this Question
Share on Google+
4 Replies


P: n/a
On Nov 20, 12:35*am, srinivasan srinivas <sri_anna...@yahoo.co.in>
wrote:
<null>

| >>import math
| >>num = 123.4567
| >>math.modf(num)
| (0.45669999999999789, 123.0)
Nov 19 '08 #2

P: n/a
On Nov 19, 1:44*pm, John Machin <sjmac...@lexicon.netwrote:
On Nov 20, 12:35*am, srinivasan srinivas <sri_anna...@yahoo.co.in>
wrote:
<null>

| >>import math
| >>num = 123.4567
| >>math.modf(num)
| (0.45669999999999789, 123.0)
def frac(n):
return n - int(n)
Nov 19 '08 #3

P: n/a
"MRAB" <go****@mrabarnett.plus.comwrote in message
news:27**********************************@w1g2000p rk.googlegroups.com...
On Nov 19, 1:44 pm, John Machin <sjmac...@lexicon.netwrote:
On Nov 20, 12:35 am, srinivasan srinivas <sri_anna...@yahoo.co.in>
wrote:
<null>

| >>import math
| >>num = 123.4567
| >>math.modf(num)
| (0.45669999999999789, 123.0)
def frac(n):
return n - int(n)
n % 1.0

Nov 19 '08 #4

P: n/a
On Nov 20, 3:38*am, "Blind Anagram" <nob...@nowhere.orgwrote:
"MRAB" <goo...@mrabarnett.plus.comwrote in message

news:27**********************************@w1g2000p rk.googlegroups.com...
On Nov 19, 1:44 pm, John Machin <sjmac...@lexicon.netwrote:
On Nov 20, 12:35 am, srinivasan srinivas <sri_anna...@yahoo.co.in>
wrote:
<null>
| >>import math
| >>num = 123.4567
| >>math.modf(num)
| (0.45669999999999789, 123.0)

def frac(n):
* * return n - int(n)

n % 1.0
| >>n= -123.4567
| >>n % 1.0
| 0.54330000000000211
Nov 19 '08 #5

This discussion thread is closed

Replies have been disabled for this discussion.