Results 1 to 2 of 2
- 01-15-2012, 08:29 PM #1
Member
- Join Date
- Jan 2012
- Posts
- 45
- Rep Power
- 0
decimal to simplest form fraction
I'm making a simple calculator with the ability to convert a decimal figure, like 1.25 in to 1 1/4.
However, programming and math are both flinching areas for me.
Say my calculator screen says 1.28.
I've been thinking I could use the "." as a break point and grab the real numbers that way, and count the decimals after it. That way I can make it in to a fraction, but then I can't figure out how to bring it down to simplest terms.
In theory, I could use indexOf on the "." and somehow grab the real number from before it and count the decimals after it.
Now I would have 1 28/100. Simple enough I could just divide by two, but as the decimal figure can be anything, dividing by two won't always obviously cut it.
Help a noob, would ya? :)
- 01-15-2012, 08:34 PM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,394
- Blog Entries
- 7
- Rep Power
- 17
Similar Threads
-
Decimal to binary, octal to decimal
By matejm1994 in forum New To JavaReplies: 3Last Post: 12-26-2010, 09:59 AM -
Simplest code won't work, help needed
By goose87 in forum New To JavaReplies: 5Last Post: 10-30-2010, 06:17 PM -
Decimal to Fraction method
By Chasingxsuns in forum New To JavaReplies: 2Last Post: 07-16-2009, 02:42 AM -
Simplest SWT application
By Java Tip in forum SWTReplies: 0Last Post: 07-02-2008, 08:12 PM -
Simplest ApplicationWindow Example
By Java Tip in forum SWTReplies: 0Last Post: 07-02-2008, 08:12 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks