fractions

Detect single string fraction (ex: ½ ) and change it to longer string?

喜你入骨 提交于 2020-01-30 07:33:26
问题 ex: "32 ½ is not very hot " to x = "info: 32, numerator = 1, denominator = 2" Note: it could be 3/9 , but it cannot be simplified into 1/3 aka literally get what is in the string. I need to detect the fractional string in a longer string and expand the information to a more usable form. ½ has been given to me decoded and is a string with length one. 回答1: There seem to be 19 such forms (here) and they all start with the name VULGAR FRACTION. import unicodedata def fraction_finder(s): for c in

C# unlimited significant decimal digits (arbitrary precision) without java [duplicate]

霸气de小男生 提交于 2020-01-27 08:46:16
问题 This question already has answers here : Closed 9 years ago . Possible Duplicate: what is the equivalent for java class : BigDecimal in c# I know in this post: Arbitrary precision decimals in C#? says to use java.math.BigDecimal, but I don't have J# installed. How would I achieve arbitrary precision in C#? I was thinking of using binary strings but I may run into some trouble when multiplying the two. 回答1: See What is the equivalent of the Java BigDecimal class in C#? You could create your

C# unlimited significant decimal digits (arbitrary precision) without java [duplicate]

≡放荡痞女 提交于 2020-01-27 08:42:10
问题 This question already has answers here : Closed 9 years ago . Possible Duplicate: what is the equivalent for java class : BigDecimal in c# I know in this post: Arbitrary precision decimals in C#? says to use java.math.BigDecimal, but I don't have J# installed. How would I achieve arbitrary precision in C#? I was thinking of using binary strings but I may run into some trouble when multiplying the two. 回答1: See What is the equivalent of the Java BigDecimal class in C#? You could create your

Calculate period length of recurring decimal fraction

痞子三分冷 提交于 2020-01-24 19:24:00
问题 I want to do a program in python (3.6.5) that tell the length of e.g. 1/7. The output should be for this example something like: "length: 6, repeated numbers: 142857". I got this so far: n = int(input("numerator: ")) d = int(input("denominator: ")) def t(n, d): x = n * 9 z = x k = 1 while z % d: z = z * 10 + x k += 1 print ("length:", k) print ("repeated numbers:", t) return k, z / d t(n, d) 回答1: Doing print ("repeated numbers:", t) prints the representation of the t function itself, not its

Calculate period length of recurring decimal fraction

会有一股神秘感。 提交于 2020-01-24 19:23:13
问题 I want to do a program in python (3.6.5) that tell the length of e.g. 1/7. The output should be for this example something like: "length: 6, repeated numbers: 142857". I got this so far: n = int(input("numerator: ")) d = int(input("denominator: ")) def t(n, d): x = n * 9 z = x k = 1 while z % d: z = z * 10 + x k += 1 print ("length:", k) print ("repeated numbers:", t) return k, z / d t(n, d) 回答1: Doing print ("repeated numbers:", t) prints the representation of the t function itself, not its

Ruby Regex to round trailing zeros

二次信任 提交于 2020-01-11 05:26:09
问题 I'm looking for a regex to remove trailing zeros from decimal numbers. It should return the following results: 0.0002300 -> 0.00023 10.002300 -> 10.0023 100.0 -> 100 1000 -> 1000 0.0 -> 0 0 -> 0 Basically, it should remove trailing zeros and trailing decimal point if the fraction part is 0. It should also return 0 when that's the value. Any thoughts? thanks. 回答1: Try the regex: (?:(\..*[^0])0+|\.0+)$ and replace it with: \1 A demo: tests = ['0.0002300', '10.002300', '100.0', '1000', '0.0', '0

How can I make a “working” repeating decimal representation of a rational number?

╄→尐↘猪︶ㄣ 提交于 2020-01-09 19:27:28
问题 I've figured out how to display the repeating part of a repeating decimal using OverBar. repeatingDecimal doesn't actually work as a repeating decimal. I'd like to make a variation of it that looks and behaves like a repeating decimal. Question How could I make a working repeating decimal representation (possibly using Interpretation[] )? Background Please excuse me if I ramble. This is my first question and I wanted to be clear about what I have in mind. The following will "draw" a repeating

Using Fractions On Websites

梦想与她 提交于 2020-01-09 12:02:06
问题 Is it possible to use any fraction symbol on a website, represented as ¼ rather than 1/4 for example? From what I've gathered, these are the only ones I can use: ½ ⅓ ⅔ ¼ ¾ Is this right and why is that? The reason why I ask this is because I've done a Google web search and can't seem to locate any others ... eg. 2/4 回答1: You can test http://www.mathjax.org/ it is a JavasScript library to make a Math Formula if this is what you want. 回答2: The image below displays all unicode-defined fraction

Using Fractions On Websites

喜欢而已 提交于 2020-01-09 12:02:05
问题 Is it possible to use any fraction symbol on a website, represented as ¼ rather than 1/4 for example? From what I've gathered, these are the only ones I can use: ½ ⅓ ⅔ ¼ ¾ Is this right and why is that? The reason why I ask this is because I've done a Google web search and can't seem to locate any others ... eg. 2/4 回答1: You can test http://www.mathjax.org/ it is a JavasScript library to make a Math Formula if this is what you want. 回答2: The image below displays all unicode-defined fraction

Convert percentage to nearest fraction

左心房为你撑大大i 提交于 2020-01-03 08:48:15
问题 We have a very data intensive system. It stores raw data, then computes percentages based on the number of correct responses / total trials. Recently we have had customers who want to import old data into our system. I need a way to covert a percentage to the nearest fraction. Examples. 33% needs to give me 2/6. EVEN though 1/3 is .33333333 67% needs to give me 4/6. EVEN though 4/6 is .6666667 I realize I could just compute that to be 67/100, but that means i'd have to add 100 data points to