944,111 Members | Top Members by Rank

Ad:
  • Python Discussion Thread
  • Marked Solved
  • Views: 687
  • Python RSS
Oct 19th, 2009
0

Ipart - Fpart

Expand Post »
I need to split a float in 2, but the split function doesnt work with floats...
What is an alternative for this?

If I have 2.4 I want to get 2 and 4
In math you've got a function fpart and ipart, but I don't know this is possible in python...
Similar Threads
Reputation Points: 25
Solved Threads: 11
Posting Whiz in Training
Kruptein is offline Offline
258 posts
since Sep 2009
Oct 19th, 2009
1
Re: Ipart - Fpart
Let's assume you want something like this ...
python Syntax (Toggle Plain Text)
  1. x = 123.456
  2.  
  3. ipart, fpart = str(x).split('.')
  4.  
  5. print ipart, fpart
Last edited by vegaseat; Oct 19th, 2009 at 1:40 pm.
Moderator
Reputation Points: 1333
Solved Threads: 1404
DaniWeb's Hypocrite
vegaseat is offline Offline
5,792 posts
since Oct 2004
Oct 19th, 2009
0
Re: Ipart - Fpart
Okay that was quit stupid :f
Reputation Points: 25
Solved Threads: 11
Posting Whiz in Training
Kruptein is offline Offline
258 posts
since Sep 2009
Oct 19th, 2009
0
Re: Ipart - Fpart
Click to Expand / Collapse  Quote originally posted by Kruptein ...
Okay that was quit stupid :f
Asking questions is never stupid!
Reputation Points: 404
Solved Threads: 180
Nearly a Posting Virtuoso
bumsfeld is offline Offline
1,422 posts
since Jul 2005
Oct 19th, 2009
0
Re: Ipart - Fpart
Alternately you could use modulus division like this:
python Syntax (Toggle Plain Text)
  1. >>> f = 123.456
  2. >>> ipart = int(f)
  3. >>> fpart = f % 1
  4. >>> ipart
  5. 123
  6. >>> fpart
  7. 0.45600000000000307
  8. >>>
Reputation Points: 355
Solved Threads: 292
Veteran Poster
jlm699 is offline Offline
1,102 posts
since Jul 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Python Forum Timeline: numtolet
Next Thread in Python Forum Timeline: ??OOP??





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC