- Home /

# 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

**Answer** by Fanboy
·
Feb 19, 2011 at 03:02 AM

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.

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?

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.

### Your answer

### Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.

### Follow this Question

### Related Questions

Can someone help me fix my Javascript for Flickering Light? 6 Answers

Maths with variables 2 Answers

Javascript rounding off a decimal 0 Answers

print to only two decimal places. 2 Answers