fractions

Is JavaScript's Math broken?

0.1 + 0.2 == 0.3 // returns false 0.1 + 0.2 // returns 0.30000000000000004 Any ideas why this happens? ...

Converting fractions to html entities

We've got some fraction information stored in the database, e.g. ¾ ½ Short of doing a search and replace, are there any inbuilt PHP functions that will automatically convert these to proper html entities? ...

A way to get a math answer in fraction form

I'm trying to write a program that will help someone study for the GRE math. As many of you may know, fractions are a big part of the test, and calculators aren't allowed. Basically what I want to do is generate four random numbers (say, 1-50) and either +-/* them and then accept an answer in fraction format. The random number thing is e...

Passing the values to the fraction class in java

If i was to make a new program and wanted to have a fraction class and what my book calls a driver class wich is a main class and i have code like this // Driver class import java.util.Scanner; public class DriverClass{ public static void main(String[] args){ Scanner stdIn = new Scanner(System.in); Fraction c, d;...

My problem is how do i make this work

import java.util.Scanner; public class Fraction { private int numerator; private int denominator; private int product; private int sum; public Fraction(int num, int denom) { this.numerator=num; this.denominator=denom; if (this.denominator == 0){ System.out.println("can not divide by zero"); }// end if }// end fraction ...

Finding if two numbers have the same digit and then remove them from in the original number in Haskell

Hi I am doing project euler question 33 and have divised a refactor to solve it but I can't think of how to remove the digit if it is the same across both x and y. I got this far: import Ratio import List p33 = [ (x%y) | y <- [10..99] , x <- [10..y], (x `rem` 10) /= 0 , (y `rem` 10) /= 0 , x /= y , (length $ nub $ concat $ map decToLis...

How can I turn a floating point number into the closest fraction represented by a byte numerator and denominator?

How can I write an algorithm that given a floating point number, and attempts to represent is as accurately as possible using a numerator and a denominator, both restricted to the range of a Java byte? The reason for this is that an I2C device wants a numerator and denominator, while it would make sense to give it a float. For example,...

Excel's cell center shifted

Hi community, I have been working on a math drill program for a bit now. I had asked a similar question to this previously but I wasn't getting any good help with it. So I decided to research the problem more thoroughly and found something interesting. Now before I begin, I just want to go over the preliminaries. Yes, I am using Micros...

PHP convert decimal into fraction and back?

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 conver...

problem with fraction reducer application

I'll get to this quick: I have an application for the iPhone OS 3.1.2 that will reduce fractions. I have 4 outlets: oTop and oBottom: two UITextFields, stands for originalTop and originalBottom. rTop and rBottom: two UILabels, stands for reducedTop and reducedBottom. Here is the code I use: -(IBAction)reduce { int numerator = [[oTop...

How to display pretty fractions in Crystal Reports generated PDF

I'm exporting a report to PDF using Crystal Reports bundled with VS2008. I need to display non-standard fractions so that they look nice instead of just something like 26/32. I have turned html interpretation on for the field so &frac12; and other standard html fraction entities display nicely, however, because CR does not understand <s...

ASP .NET text box that supports fractions and imperial to metric conversion

I am developing in ASP .NET, C#. I'm looking for third party components that support the following requirements: 1) Ability to enter information into a numeric (preferably spin button enabled) text box as fractions. 2) Support for conversion between fractions and decimal. 3) Support for conversion between metric and imperial units of...

Turning Floats into Their Closest (UTF-8 Character) Fraction.

I want to take any real number, and return the closest number, with the closest fraction as available in the UTF-8 character set, appropriate. 0/4 = 0.00 = # < .125 1/4 = 0.25 = ¼ # > .125 & < .375 2/4 = 0.50 = ½ # > .375 & < .625 3/4 = 0.75 = ¾ # > .625 & < .875 4/4 = 1.00 = # > .875 I made this function to do that task: functio...

Calculating negative fractions in Objective C

I've been coding my way through Steve Kochan's Programming in Objective-C 2.0 book. I'm up to an exercise in chapter 7, ex 4, in case anyone has the book. The question posed by the exercise it will the Fraction class written work with negative fractions such as -1/2 + -2/3? Here's the implementation code in question - @implementation ...

Python: avoiding fraction simplification

Hi all, I'm working on a music app' in Python and would like to use the fractions module to handle time signatures amongst other things. My problem is that fractions get simplified, i.e.: >>> from fractions import Fraction >>> x = Fraction(4, 4) >>> x Fraction(1, 1) However, it is important from a musical point of view that 4/4 stays...

How to simplify fractions in C#?

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 fracti...

C++ User Input When Initializing Values

Hello. I'm a student in an introductory C++ course. For one of our past assignments we have had to create a simple program to add fractions. Each new lab is just an application of new skills learned to making the same program. Now I need to make one using objects from a class definition. After tooling with a multiplying example my pro...

Get the integral part of a BigFraction, as a BigInteger

What is an easy way to get the integral part of a BigFraction as a BigInteger? Basically I want the same result that the intValue and longValue methods return but with arbitrary precision. I also want to avoid rounding so indirect conversion via a BigDecimal is not suitable. ...

Convert list of Fractions to floats in Python

I have a list of fractions, such as: data = ['24/221 ', '25/221 ', '24/221 ', '25/221 ', '25/221 ', '30/221 ', '31/221 ', '31/221 ', '31/221 ', '31/221 ', '30/221 ', '30/221 ', '33/221 '] How would I go about converting these to floats, e.g. data = ['0.10 ', '0.11 ', '0.10 ', '0.11 ', '0.13 ', '0.14 ', '0.14 ', '0.14 ', '0.14 ', '0.14...

What is the easiest way to parse a string and replace 1/2 with ½ (and similar) in PHP?

I have a string with many fractions like 1/2, 1/4 etc. I want to replace them with their Unicode equivalents. I realise I could pick them up with /\s(\d+)\/(\d+)\s/ How would I replace them with their Unicode equivalents? I could probably wrap the numbers in span and do something similar with CSS, but I was wondering if there was an ...