PC Review


Reply
Thread Tools Rate Thread

Deriving decimal from fraction

 
 
arun.hallan@gmail.com
Guest
Posts: n/a
 
      14th Jul 2006
I need to derive fractions from decimals as so:

0.3333 = 1/3
0.6666 = 2/3

The decimal could also be 0.33, or 0.3333333 but the point is that it
that the fraction needs to be extracted.

The reason for this is a UI restriction, where users can only enter a
percentage. But in the case where a third needs to be expressed, a
decimal will never be as accurate as teh fraction.


Thanks,
Arun

 
Reply With Quote
 
 
 
 
arun.hallan@gmail.com
Guest
Posts: n/a
 
      14th Jul 2006
Sorry, the title of this post should be

Deriving fraction from decimal

 
Reply With Quote
 
Kevin Spencer
Guest
Posts: n/a
 
      14th Jul 2006
Your question doesn't make sense. You are correct in that a decimal is not
(necessarily) as accurate as a fraction, but a fraction derived from a
decimal will always be only as accurate as the decimal it was derived from.
For example, let's look at your example:

0.3333 = 1/3

This is incorrect. 0.3333 and 1/3 are 2 entirely different values. 1/3 is
greater than 0.3333. So, there is no way to derive 1/3 from 0.3333. You
*could* derive a fraction from it, but it would not be 1/3. In fact, you
could not derive 0.3333 from 1/3, as they are not equal. 1/3 cannot be
expressed in decimal numbers.

The formula is simple algebra. 1/3 is an expression that indicates 1 divided
by 3. So, let's start out with a fraction that *can* be converted to a
decimal:

0.25 = 1/4

This means that 0.25 is equal to 1 divided by 4. This could be expressed
using variables as:

x = y / z

From algebra, we know that to resolve for y, we use:

y = x * z

To resolve for z:

z = y / x

So, to derive 1 / 4 from 0.25, you would say:

0.25 = y / z

Now, it is important to note here that any number of fractions can be
derived from a decimal. For example:

0.25 = 1 / 4
0.25 = 2 / 8
0.25 = 3 / 12

So, all we have to do is plug in an arbitrary number into either the 'y' or
'z' variable to derive the other:

0.25 = 2 / z
2 / 0.25 = z
2 / .25 = 8
0.25 = 2 / 8

Of course, depending on what value you plug in, you may get a decimal or
fractional result for the other:

0.25 = 3 / z
3 / 0.25 = z
3 / 0.25 = 0.75
0.25 = 3 / 0.75

An easy fix is to use the original decimal, converted to a whole number, to
ensure a whole fraction:

0.25 = 25 / z
0.25 / 25 = z
0.25 / 25 = 100
0.25 = 25 / 100

If you want to, you can reduce the fraction, but I'm sure you know how to do
that.

In any case, as I said, you're not going to get any more accurate this way.
Because fractions *are* more accurate than decimals, you will never achieve
greater accuracy by converting a decimal to a fraction.

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Chicken Salad Alchemist

What You Seek Is What You Get.


<(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>I need to derive fractions from decimals as so:
>
> 0.3333 = 1/3
> 0.6666 = 2/3
>
> The decimal could also be 0.33, or 0.3333333 but the point is that it
> that the fraction needs to be extracted.
>
> The reason for this is a UI restriction, where users can only enter a
> percentage. But in the case where a third needs to be expressed, a
> decimal will never be as accurate as teh fraction.
>
>
> Thanks,
> Arun
>



 
Reply With Quote
 
Rick Lones
Guest
Posts: n/a
 
      14th Jul 2006
(E-Mail Removed) wrote:
> I need to derive fractions from decimals as so:
>
> 0.3333 = 1/3
> 0.6666 = 2/3
>
> The decimal could also be 0.33, or 0.3333333 but the point is that it
> that the fraction needs to be extracted.
>
> The reason for this is a UI restriction, where users can only enter a
> percentage. But in the case where a third needs to be expressed, a
> decimal will never be as accurate as teh fraction.


0.3333 = 3333/10000
0.6666 = 3333/5000

The problem here is that both of your examples have a natural and well-defined
fraction representation - it's just not the one you want.

You are getting into AI ("read my mind") territory here I am afraid. I think
that IF you really need an explicit numerator and denominator then you will need
to change the UI to accept them in that form. (And the program to work with
them in that form as well, of course.) You will never get an exact
representation of 1/3 in floating point. What is driving this requirement for
an exact representation? An education-based app of some kind?

-rick-
 
Reply With Quote
 
arun.hallan@gmail.com
Guest
Posts: n/a
 
      14th Jul 2006
Sorry, i should have made myself clearer.
And Kevin, i have a mathematically based computer science degree, and
understand fractions!

I am worknig on an old system. The UI allows percentages to be added.
So if we have a number, say 1000000, and you want to represent 20%, you
can enter 20%.

But what if you want to enter a third?

The only solution i can see is to write code to round numbers such as
0.3333 to a third.

YES i know it's not accurate, and i know the difference between 0.3333
and 1/3.

I'm just asking if there is a better solution to this, in the same way
as a human can look at 0.3333 and intuitively know that the value is
around a third.

Thanks
Arun

Rick Lones wrote:

> (E-Mail Removed) wrote:
> > I need to derive fractions from decimals as so:
> >
> > 0.3333 = 1/3
> > 0.6666 = 2/3
> >
> > The decimal could also be 0.33, or 0.3333333 but the point is that it
> > that the fraction needs to be extracted.
> >
> > The reason for this is a UI restriction, where users can only enter a
> > percentage. But in the case where a third needs to be expressed, a
> > decimal will never be as accurate as teh fraction.

>
> 0.3333 = 3333/10000
> 0.6666 = 3333/5000
>
> The problem here is that both of your examples have a natural and well-defined
> fraction representation - it's just not the one you want.
>
> You are getting into AI ("read my mind") territory here I am afraid. I think
> that IF you really need an explicit numerator and denominator then you will need
> to change the UI to accept them in that form. (And the program to work with
> them in that form as well, of course.) You will never get an exact
> representation of 1/3 in floating point. What is driving this requirement for
> an exact representation? An education-based app of some kind?
>
> -rick-


 
Reply With Quote
 
Bruce Wood
Guest
Posts: n/a
 
      14th Jul 2006

(E-Mail Removed) wrote:
> Sorry, i should have made myself clearer.
> And Kevin, i have a mathematically based computer science degree, and
> understand fractions!
>
> I am worknig on an old system. The UI allows percentages to be added.
> So if we have a number, say 1000000, and you want to represent 20%, you
> can enter 20%.
>
> But what if you want to enter a third?
>
> The only solution i can see is to write code to round numbers such as
> 0.3333 to a third.
>
> YES i know it's not accurate, and i know the difference between 0.3333
> and 1/3.
>
> I'm just asking if there is a better solution to this, in the same way
> as a human can look at 0.3333 and intuitively know that the value is
> around a third.
>
> Thanks
> Arun


Kevin is right: you have to know the denominator in order to round to
the closest enumerator. The only approach I can suggest is an iterative
one: pick a range of denominators, try each one, and pick the one that
is the closest approximation to the decimal that the user entered. You
could use a tolerance, too, and if none of the values is within
tolerance then reject them all and use the decimal instead.

 
Reply With Quote
 
Thomas T. Veldhouse
Guest
Posts: n/a
 
      14th Jul 2006
(E-Mail Removed) wrote:
> I need to derive fractions from decimals as so:
>
> 0.3333 = 1/3
> 0.6666 = 2/3
>
> The decimal could also be 0.33, or 0.3333333 but the point is that it
> that the fraction needs to be extracted.
>
> The reason for this is a UI restriction, where users can only enter a
> percentage. But in the case where a third needs to be expressed, a
> decimal will never be as accurate as teh fraction.
>
>


There is an old method of doing this by using a Farey Sequence. I used to
play with the pattern as kid and was pleasantly surprised that I didn't invent
it ;-)

So, a nice search finds a good example at Dr. Dobbs.

http://www.ddj.com/184409653

--
Thomas T. Veldhouse
Key Fingerprint: 2DB9 813F F510 82C2 E1AE 34D0 D69D 1EDC D5EC AED1

 
Reply With Quote
 
Rick Lones
Guest
Posts: n/a
 
      14th Jul 2006
Yeah, that's what I mean by "AI territory". Your desired inference, that 0.3333
= 1/3, is not possible in general without some explicit indication of where the
repeating decimals occur.

If I input ".3636" how do you (meaning some dumb program) know whether I want:
a) .3636 exactly, or
b) .36366666 . . ., or
c) .3636363636 . . . ?

I think you are stuck in general unless you can obtain additional hints via the
UI, as per, e.g.,
a) .3636,
b) .363(6),
c) .(36)

-rick-

(E-Mail Removed) wrote:
> Sorry, i should have made myself clearer.
> And Kevin, i have a mathematically based computer science degree, and
> understand fractions!
>
> I am worknig on an old system. The UI allows percentages to be added.
> So if we have a number, say 1000000, and you want to represent 20%, you
> can enter 20%.
>
> But what if you want to enter a third?
>
> The only solution i can see is to write code to round numbers such as
> 0.3333 to a third.
>
> YES i know it's not accurate, and i know the difference between 0.3333
> and 1/3.
>
> I'm just asking if there is a better solution to this, in the same way
> as a human can look at 0.3333 and intuitively know that the value is
> around a third.
>
> Thanks
> Arun
>
> Rick Lones wrote:
>
>> (E-Mail Removed) wrote:
>>> I need to derive fractions from decimals as so:
>>>
>>> 0.3333 = 1/3
>>> 0.6666 = 2/3
>>>
>>> The decimal could also be 0.33, or 0.3333333 but the point is that it
>>> that the fraction needs to be extracted.
>>>
>>> The reason for this is a UI restriction, where users can only enter a
>>> percentage. But in the case where a third needs to be expressed, a
>>> decimal will never be as accurate as teh fraction.

>> 0.3333 = 3333/10000
>> 0.6666 = 3333/5000
>>
>> The problem here is that both of your examples have a natural and well-defined
>> fraction representation - it's just not the one you want.
>>
>> You are getting into AI ("read my mind") territory here I am afraid. I think
>> that IF you really need an explicit numerator and denominator then you will need
>> to change the UI to accept them in that form. (And the program to work with
>> them in that form as well, of course.) You will never get an exact
>> representation of 1/3 in floating point. What is driving this requirement for
>> an exact representation? An education-based app of some kind?
>>
>> -rick-

>

 
Reply With Quote
 
Kevin Spencer
Guest
Posts: n/a
 
      14th Jul 2006
Hi Arun,

If you want a human to look at the number and intuitively know what the
amount is, think graphics. Humans do not natively understand numbers. We
have to be taught to think in terms of numbers. But our brains are actually
incredibly accurate computers, as exemplified by, for example, a figure
skater. The calculations required to maintain balance while perched on top
of a couple of pieces of metal while sliding across an ice surface and
performing leaps, twirls, and jumps, is something no computer can do.

What humans *do* understand is graphics. We see from the time we are born,
and learn to calculate by sight, how large things are, how far away they
are, etc. This is why pie charts are so popular. So, what about displaying a
pie chart, a graph, or some other visual representation of the number?

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Chicken Salad Alchemist

What You Seek Is What You Get.


<(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Sorry, i should have made myself clearer.
> And Kevin, i have a mathematically based computer science degree, and
> understand fractions!
>
> I am worknig on an old system. The UI allows percentages to be added.
> So if we have a number, say 1000000, and you want to represent 20%, you
> can enter 20%.
>
> But what if you want to enter a third?
>
> The only solution i can see is to write code to round numbers such as
> 0.3333 to a third.
>
> YES i know it's not accurate, and i know the difference between 0.3333
> and 1/3.
>
> I'm just asking if there is a better solution to this, in the same way
> as a human can look at 0.3333 and intuitively know that the value is
> around a third.
>
> Thanks
> Arun
>
> Rick Lones wrote:
>
>> (E-Mail Removed) wrote:
>> > I need to derive fractions from decimals as so:
>> >
>> > 0.3333 = 1/3
>> > 0.6666 = 2/3
>> >
>> > The decimal could also be 0.33, or 0.3333333 but the point is that it
>> > that the fraction needs to be extracted.
>> >
>> > The reason for this is a UI restriction, where users can only enter a
>> > percentage. But in the case where a third needs to be expressed, a
>> > decimal will never be as accurate as teh fraction.

>>
>> 0.3333 = 3333/10000
>> 0.6666 = 3333/5000
>>
>> The problem here is that both of your examples have a natural and
>> well-defined
>> fraction representation - it's just not the one you want.
>>
>> You are getting into AI ("read my mind") territory here I am afraid. I
>> think
>> that IF you really need an explicit numerator and denominator then you
>> will need
>> to change the UI to accept them in that form. (And the program to work
>> with
>> them in that form as well, of course.) You will never get an exact
>> representation of 1/3 in floating point. What is driving this
>> requirement for
>> an exact representation? An education-based app of some kind?
>>
>> -rick-

>



 
Reply With Quote
 
arun.hallan@gmail.com
Guest
Posts: n/a
 
      17th Jul 2006
Thanks - i think there's something i could look at.

Thomas T. Veldhouse wrote:

> (E-Mail Removed) wrote:
> > I need to derive fractions from decimals as so:
> >
> > 0.3333 = 1/3
> > 0.6666 = 2/3
> >
> > The decimal could also be 0.33, or 0.3333333 but the point is that it
> > that the fraction needs to be extracted.
> >
> > The reason for this is a UI restriction, where users can only enter a
> > percentage. But in the case where a third needs to be expressed, a
> > decimal will never be as accurate as teh fraction.
> >
> >

>
> There is an old method of doing this by using a Farey Sequence. I used to
> play with the pattern as kid and was pleasantly surprised that I didn't invent
> it ;-)
>
> So, a nice search finds a good example at Dr. Dobbs.
>
> http://www.ddj.com/184409653
>
> --
> Thomas T. Veldhouse
> Key Fingerprint: 2DB9 813F F510 82C2 E1AE 34D0 D69D 1EDC D5EC AED1


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Fraction to decimal Alvin Microsoft Excel Programming 1 18th Apr 2010 10:48 PM
Re: Help with formula (decimal to fraction) Ron Rosenfeld Microsoft Excel Worksheet Functions 0 24th Oct 2009 02:40 PM
How can I turn a fraction into a decimal. sharder Microsoft Excel Worksheet Functions 0 15th Oct 2009 05:09 PM
RE: How can I turn a fraction into a decimal. Megan Microsoft Excel Worksheet Functions 0 15th Oct 2009 04:54 PM
Converting a fraction to decimal =?Utf-8?B?R2VvcmdlIFI=?= Microsoft Access Forms 4 8th May 2007 10:41 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:34 PM.