x


decimal to fraction (just display)

hey, how do I go about taking a two decimal place decimal number and showing it as a fraction? Just in the GUI.Label so value / value would still be fine. :D

more ▼

asked Feb 19 '11 at 02:34 AM

Jason Hamilton gravatar image

Jason Hamilton
445 68 73 80

(comments are locked)
10|3000 characters needed characters left

1 answer: sort newest

Multiply it by 100, and then put it over 100.

For example: 0.77 becomes 77/100

eg:

string Frac = Convert.ToInt32(MyDecimal*100).ToString()+"/100";

You can attempt to reduce it to it's lowest common denominator if you wish, but thats more work. Not much more, but more.

more ▼

answered Feb 19 '11 at 03:02 AM

Fanboy gravatar image

Fanboy
309 1 1 4

It worked, but about that finding the LCM.... how do I find the factors of a number (in javascript :P) and compare them to the factors of 100?

Feb 19 '11 at 05:24 AM Jason Hamilton

You just loop through each possible integer from the numerator down to 2, and attempt to divide both the numerator and denominator by that number. if the result of both has no remainder, you have found the lowest common denominator.

Feb 19 '11 at 06:49 AM Fanboy
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x3465
x24
x21
x5

asked: Feb 19 '11 at 02:34 AM

Seen: 1286 times

Last Updated: Feb 19 '11 at 02:34 AM