Questions tagged [fractions]

Fractions, or "fractional numbers" (lit. "broken numbers"), or "rational numbers", are numbers expressed as the ratio of two integers, such as 1/2 or 23/17.

In computing and programming, fractional (or "rational") numbers are an alternative to floating point numbers: Since numerator and denominator are stored as integers, the representation is exact, as opposed to most floating point implementations, which cannot represent most rational numbers exactly. Arbitrary-precision ("bignum") libraries usually contain support for rational numbers.

800 questions
19
votes
11 answers

Is there any controls available for star rating?

Is there any controls available for star rating in ios ? So i can use that in UITableviewCell ?? I know there are some open open source controls like DYRating etc.. But iam not able to add it in tableview cell .
Naveen
  • 1,251
  • 9
  • 20
  • 38
19
votes
12 answers

Convert a decimal number to a fraction / rational number

In JavaScript, is there any way to convert a decimal number (such as 0.0002) to a fraction represented as a string (such as "2/10000")? If a function called decimalToFraction had been written for this purpose, then decimalToFraction(0.0002) would…
Anderson Green
  • 30,230
  • 67
  • 195
  • 328
17
votes
1 answer

Best way to convert fractions.Fraction to decimal.Decimal?

In Python, the fractions.Fraction and decimal.Decimal standard library classes exist to help keep arithmetic with rational numbers precise. For the unfamiliar, an example of where it helps: >>> 1 / 10 * 3 0.30000000000000004 >>> decimal.Decimal('1')…
Dan Passaro
  • 4,211
  • 2
  • 29
  • 33
16
votes
6 answers

How to rendering fraction in Swing JComponents

Basically Swing JComponents are able to display numbers in fractions in this form 2 2/3. How can I paint fraction in the nicest form, for example 2⅔? . EDIT . as see I have only one way JTable inside JSpinner with one TableColumn and TableRow (that…
mKorbel
  • 109,525
  • 20
  • 134
  • 319
16
votes
1 answer

Call to non-static member function without an object argument

Can anyone explain this error any why I am getting it? I believe I've got all of the arithmetic down in my separate class. This program stores and manipulates fractions, while testing overloading. Thank you in advance. I am trying to test this in…
MatthewTingle
  • 355
  • 2
  • 3
  • 12
15
votes
7 answers

Finding the closest integer fraction to a given random real between 0..1, given ranges of numerator and denominator

Given two ranges of positive integers x: [1 ... n] and y: [1 ... m] and random real R from 0 to 1, I need to find the pair of elements (i,j) from x and y such that x_i / y_j is closest to R. What is the most efficient way to find this pair?
13
votes
2 answers

How to use numpy arrays with fractions?

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…
Jkev
  • 177
  • 1
  • 2
  • 8
13
votes
3 answers

Decimal to Fraction conversion in Swift

I am building a calculator and want it to automatically convert every decimal into a fraction. So if the user calculates an expression for which the answer is "0.333333...", it would return "1/3". For "0.25" it would return "1/4". Using GCD, as…
owlswipe
  • 19,159
  • 9
  • 37
  • 82
13
votes
3 answers

What algorithm does Python employ in fractions.gcd()?

I'm using the fractions module in Python v3.1 to compute the greatest common divisor. I would like to know what algorithm is used. I'm guessing the Euclidean method, but would like to be sure. The docs…
Justin R.
  • 23,435
  • 23
  • 108
  • 157
12
votes
5 answers

What is the best way to separate double into two parts "integer & fraction" in java

I have tried to separate 5.6 (for example) by the following method: private static double[] method(double d) { int integerPart = 0; double fractionPart = 0.0; integerPart = (int) d; fractionPart = d - integerPart; return new…
Eng.Fouad
  • 115,165
  • 71
  • 313
  • 417
12
votes
2 answers

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

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…
DavidC
  • 3,056
  • 1
  • 20
  • 30
12
votes
10 answers

How to convert decimal to fractions?

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); …
Dil.
  • 1,996
  • 7
  • 41
  • 68
11
votes
6 answers

Converting a float into a string fraction representation

In Java, I am trying to find a way to convert a float number into a fraction string. For example: float num = 1.33333; String numStr = Convert(num); // Should return "1 1/3" float num2 = 1.333; String numStr2 = Convert(num2); // Should also return…
Icemanind
  • 47,519
  • 50
  • 171
  • 296
11
votes
3 answers

How to keep fractions in your equation output

I've been using Python to calculate math equations. For example: from sympy import Symbol, Derivative, Integral x = Symbol('x') d = Symbol('d') Integral(8*x**(6/5)-7*x**(3/2),x).doit() Which results in the output: 3.63636363636364*x**2.2 -…
d84_n1nj4
  • 1,712
  • 6
  • 23
  • 40
11
votes
4 answers

Find the simplest rational number between two given rational numbers

I found a problem related to rational numbers. Two rational numbers are given and the task is to find the simplest rational number between them. For this problem, the simplicity of a rational number could be defined as the rational number with the…
Tom Pažourek
  • 9,582
  • 8
  • 66
  • 107
1
2
3
53 54