Posts: 4,653
Threads: 1,496
Joined: Sep 2016
i want to get the whole value and fraction value of a float value i have. i converted it to string, split that by '.' (maybe it needs to be ','), then converted to ints. is there a better way? getting the whole value looks easy. is there a better way to get the fractional part?
Tradition is peer pressure from dead people
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Posts: 4,653
Threads: 1,496
Joined: Sep 2016
so fractions.Fraction(1.5) will give me 0.5?
Tradition is peer pressure from dead people
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Posts: 4,653
Threads: 1,496
Joined: Sep 2016
getting 1.5 from a string is just one way to do it. i could get 1.5 from 3.0/2.0 in python2 or python3 and get 1.5 from 3/2 in python3. there are other ways as well. getting 1 is as simple as int(1.5). getting 0.5 might work by doing 1.5-int(1.5). it did work in one test. i don't know if it will in all cases. maybe 1.5-float(int(1.5)) ensures that it always will.
Tradition is peer pressure from dead people
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.