fractions

How to convert decimal to fractions?

拈花ヽ惹草 提交于 2019-11-29 14:01:20
What I need to convert decimal to fractions. It is easy to convert to 10's feet. 1.5 => 15/10 This can do via this code: public class Rational { private int num, denom; public Rational(double d) { String s = String.valueOf(d); int digitsDec = s.length() - 1 - s.indexOf('.'); int denom = 1; for (int i = 0; i < digitsDec; i++) { d *= 10; denom *= 10; } int num = (int) Math.round(d); this.num = num; this.denom = denom; } public Rational(int num, int denom) { this.num = num; this.denom = denom; } public String toString() { return String.valueOf(num) + "/" + String.valueOf(denom); } public static

Display fraction number in UILabel

穿精又带淫゛_ 提交于 2019-11-29 05:23:30
I am working on the app in which I have to show fraction number on label. NSMutableAttributedString * hogan = [[NSMutableAttributedString alloc] initWithString:self.toValue]; [hogan setAttributes:@{NSFontAttributeName:[UIFont fontWithName:@"DINPro-Bold" size:11.0]} range:NSMakeRange(9,6)]; UILabel *fal = [[UILabel alloc] initWithFrame:CGRectMake(100,12, 150.0, 50)]; fal.text = @""; fal.textColor = [UIColor whiteColor]; fal.backgroundColor = [UIColor redColor]; fal.font = [UIFont fontWithName:@"DINPro-Bold" size:18.0]; fal.attributedText=hogan; [self addSubview:fal]; and the Output of this code

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

无人久伴 提交于 2019-11-28 23:33:52
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 decimal. repeatingDecimal[q2_] := Module[{a}, a[{{nr__Integer}, pt_}] := StringJoin[ Map[ToString, If

Using Fractions On Websites

懵懂的女人 提交于 2019-11-28 14:46:33
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 mohammad mohsenipur You can test http://www.mathjax.org/ it is a JavasScript library to make a Math Formula if this is what you want. poitroae The image below displays all unicode-defined fraction symbols. Each of them is treated as one single character. You can use all of them

How to simplify fractions in C#?

守給你的承諾、 提交于 2019-11-28 13:44:39
I'm looking for a library or existing code to simplify fractions. Does anyone have anything at hand or any links? P.S. I already understand the process but really don't want to rewrite the wheel Update Ok i've checked out the fraction library on the CodeProject BUT the problem I have is a little bit tricker than simplifying a fraction. I have to reduce a percentage split which could be 20% / 50% / 30% (always equal to 100%) I think you just need to divide by the GCD of all the numbers. void Simplify(int[] numbers) { int gcd = GCD(numbers); for (int i = 0; i < numbers.Length; i++) numbers[i] /=

Python float to ratio

非 Y 不嫁゛ 提交于 2019-11-28 10:17:04
I try get ration of variable and get unexpected result. Can somebody explain this? >>> value = 3.2 >>> ratios = value.as_integer_ratio() >>> ratios (3602879701896397, 1125899906842624) >>> ratios[0] / ratios[1] 3.2 I using python 3.3 But I think that (16, 5) is much better solution And why it correct for 2.5 >>> value = 2.5 >>> value.as_integer_ratio() (5, 2) Use the fractions module to simplify fractions: >>> from fractions import Fraction >>> Fraction(3.2) Fraction(3602879701896397, 1125899906842624) >>> Fraction(3.2).limit_denominator() Fraction(16, 5) From the Fraction.limit_denominator()

How to use numpy arrays with fractions?

非 Y 不嫁゛ 提交于 2019-11-28 10:00:49
问题 I'm trying to implement the simplex method in Python so I need to use the Gaussian elimination on arrays. Very often fractions come up and for more clarity and precision I would like to keep the fractional form instead of using floats. I know the 'fractions' module but I'm struggling to use it. I wrote my code using this module but the arrays are always returned with floats. Isn't it possible to print an array with fractions inside ? On this basic example : >>> A array([[-1., 1.], [-2., -1.]]

Convert Fraction String to Decimal?

扶醉桌前 提交于 2019-11-28 08:59:50
I'm trying to create a javascript function that can take a fraction input string such as '3/2' and convert it to decimal—either as a string '1.5' or number 1.5 function ratio(fraction) { var fraction = (fraction !== undefined) ? fraction : '1/1', decimal = ??????????; return decimal; }); Is there a way to do this? Since no one has mentioned it yet there is a quick and dirty solution: var decimal = eval(fraction); Which has the perks of correctly evaluating all sorts of mathematical strings. eval("3/2") // 1.5 eval("6") // 6 eval("6.5/.5") // 13, works with decimals (floats) eval("12 + 3") //

PHP convert decimal into fraction and back?

余生颓废 提交于 2019-11-28 06:23:48
I want the user to be able to type in a fraction like: 1/2 2 1/4 3 And convert it into its corresponding decimal, to be saved in MySQL, that way I can order by it and do other comparisons to it. But I need to be able to convert the decimal back to a fraction when showing to the user so basically I need a function that will convert fraction string to decimal: fraction_to_decimal("2 1/4");// return 2.25 and a function that can convert a decimal to a faction string: decimal_to_fraction(.5); // return "1/2" How can I do this? I think I'd store the string representation too, as, once you run the

How to simplify fractions in C#?

▼魔方 西西 提交于 2019-11-27 19:29:51
问题 I'm looking for a library or existing code to simplify fractions. Does anyone have anything at hand or any links? P.S. I already understand the process but really don't want to rewrite the wheel Update Ok i've checked out the fraction library on the CodeProject BUT the problem I have is a little bit tricker than simplifying a fraction. I have to reduce a percentage split which could be 20% / 50% / 30% (always equal to 100%) 回答1: I think you just need to divide by the GCD of all the numbers.