| | |
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 |
Tag cloud for Python
abrupt ansi anti apache approximation array backend beginner binary book builtin calculator chmod code converter countpasswordentry curved dan08 dictionaries dictionary drive dynamic examples excel file filename float format function gui heads homework import inches input java launcher library line lines linux list lists loop mouse mysql mysqlquery number numbers numeric output parsing path phonebook plugin pointer port prime programming progressbar projects py2exe pygame pyqt pysimplewizard python random recursion redirect refresh scrolledtext software statictext statistics string strings sum table terminal text textarea thread threading time tkinter tlapse trick tricks tuple tutorial twoup ubuntu unicode urllib urllib2 variable windows wordgame write wxpython






