| | |
Ipart - Fpart
Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
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...
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...
1
#2 Oct 19th, 2009
Let's assume you want something like this ...
python Syntax (Toggle Plain Text)
x = 123.456 ipart, fpart = str(x).split('.') print ipart, fpart
Last edited by vegaseat; Oct 19th, 2009 at 1:40 pm.
May 'the Google' be with you!
0
#5 Oct 19th, 2009
Alternately you could use modulus division like this:
python Syntax (Toggle Plain Text)
>>> f = 123.456 >>> ipart = int(f) >>> fpart = f % 1 >>> ipart 123 >>> fpart 0.45600000000000307 >>>
![]() |
Similar Threads
- How to separate decimal from 2.33333 (C++)
- Trouble writing code for arithmetic calculations of complex numbers (C++)
- round (C++)
- convert from c++ to python (Python)
- c++ Question Help plz.. (C++)
- rounding function with precision (C++)
- How do I replace Enter (VB.NET)
- Need Help with complex numbers (C++)
- sms via java (Java)
Other Threads in the Python Forum
| Thread Tools | Search this Thread |
address anydbm app beginner changecolor cipher class code conversion coordinates corners curves definedlines development dictionary dynamic events examples excel feet file float font format ftp function generator getvalue gui handling homework images import input ip java keycontrol line linux list lists loan loop maintain maze millimeter mouse mysqldb number numbers output parsing path permissions port prime programming projects py2exe pygame pymailer python queue random rational raw_input recursion recursive scrolledtext searchingfile shebang slicenotation split string strings table terminal text thread threading time tkinter tlapse tooltip tuple tutorial type ubuntu unicode url urllib urllib2 variable variables vigenere web windows wx.wizard wxpython xlwt






