fractions

modf returns 1 as the fractional:

I have this static method, it receives a double and "cuts" its fractional tail leaving two digits after the dot. works almost all the time. I have noticed that when it receives 2.3 it turns it to 2.29. This does not happen for 0.3, 1.3, 3.3, 4.3 and 102.3. Code basically multiplies the number by 100 uses modf divides the integer value by...

How can fractional number expressions be parsed using pyparsing?

We've just started to kick the tires pyparsing and like it so far, but we've been unable to get it to help us parse fractional number strings to turn them into numeric data types. For example, if a column value in a database table contained the string: 1 1/2 We'd like some way to convert it into the numeric python equivalent: 1.5 We...

Math Question in JS - How do I get a ratio from a percentage

I'm trying to make a converter, but i don't know the formula to do this, for example, how do I get the ratio of 85694 of 30711152. So, i can get the % like 85694/30711152*100=0.28 (rounded) but how do I then get the ratio of like 1 in a 100? I believe that'd be around 1:400? But i don't know how to get it exactly or what formula to use.....

How to convert a special float into a fraction object

I have this function inside another function: def _sum(k): return sum([(-1) ** v * fractions.Fraction(str(bin_coeff(k, v))) * fractions.Fraction((n + v) ** m, k + 1) for v in xrange(k + 1)]) When i call fractions.Fraction on bin_coeff it reports me this error: ValueError: Invalid literal for Fraction: '1.05204948186e+12' Ho...