Converting a decimal # to a fraction #



#15

Can someone show me how to do this?

Thanks


#16

A fraction a/b is defined by the equation a/b x b = a. The term a is the numerator and term b is the denominator of the fraction. Example, 5/8 = .6250 in decimal form. Multiplying the denominator 8 x .6250 yields the answer 5 which is the numerator so you have the fraction of 5/8 again. If you see a fraction in decimal form and have no idea what the fractional equivalent may be you can try this trial and error algorithim on your calculator. Start at 2 as the denominator and multiply this with the decimal. If you get a mixed number for the numerator, then it was not the proper denominator, try again with 3, and so on until you get a whole number (not zero). Example. .6250 x 2 = 1.25. Not a proper numerator. .6250 x 3 = 1.8750 .6250 x 4 = 2.5 etc.. until, .6250 x 8 = 5 the correct numerator. This will be the only solution that will give a whole number numerator until you go to another multiple of 8 such as 16, .6250 x 16 = 10 this would be 10/8 = 1.25 which is not .6250 so you will know you went to far. If all else fails, go purchase an hp32SII which does the converting for you automatically. I hope I have helped you. Cheers Bill.


#17

What kind of calculator are you using? If you have a 48 series try using \->Q. This will return a fraction given a decimal number. ..6250 = '5/8'. rdb.


#18

\->Q ? I also like too know this trick, but wat key's must i use?

Erwin


#19

If you still need more information on using the to 'Q' function, the following may help. For an hp-48sx place a decimal number on the stack then press left shift, the orange key, and then 'EVAL', '->Q'. This will return a near approximation to the stack, i.e. pi returns '22/7'. If you are using an hp-48gx place a decimal number on the stack and then press the alpha key twice to set alpha entry mode. Then press right shift, the green key, and zero to place a right arrow on the input line, then press the large down arrow key, row three column five, to place a 'Q' after the arrow, then press 'ENTER'. Again this returns an approximation fraction. If you are using an hp-49g, use the same instructions as for the 48gx, substituting red shift for green shift and 'Q' 'Y^X' for down arrow, Also the 49g requires a switch to RAD mode for some imbecilic reason. Hope this has helped.

rdb.


#20

Aha,

That's a lot easier than than going through the menu's too get the "->Q" softkey.

Thanks, Erwin

#21

Thanks guys

#22

Hi! If you've got a 48 or a 32SII no problem: they have that function built in. For other calculators try this little program. I've implemented it on a 28S and a 42S and it works fine. You can even specify a default precission. The code below is for the 28S (48X style, but not 100% compatible!), if anyone wants the 42S code just ask for it. Copyrights: This code is a personal modification on Thomas Affinito & Jurjen E. Bos. 'Fract' program.

%decimal_number -> 'fraction' (with default precision)

%decimal_number %precission -> 'fraction'

('fraction' is EVALuable to the original number, the '6' in the first row of code is the default precission)

«

IF DUP FP THEN 6 END

NEG ALOG 2 / 1 0 4 ROLL DUP ABS 5 ROLLD SIGN

-> X P A B S

«

X ABS

WHILE 'ABS(FLOOR(X*A+.5)-X*A)>=P*A'

EVAL

REPEAT INV DUP IP ABS A * B + A 'B' STO 'A' STO FP

END

DROP 'FLOOR(X*A+.5)' EVAL S * A

»

"'" ROT ->STR + "/" + SWAP ->STR + "'" + STR->

»

Hope this helps!


#23

Got it. I thought that the 48 didn't had this function, but it's also explained on page 16-5 of the user's guide.

Thank's for the HP28s program.

The program for the HP42s, is that also suiteble for a HP41CV? If so, can you give me that?

Thank you, Erwin


#24

I've translated the HP42S 'Fract' code to a HP41C and it works, though is not as user-friendly as on the HP42S. You can find both HP42S and HP41C programs here:

http://www.geocities.com/xose_manuel2/calc/fract.txt

I've included the 42S code because it's output is nicer (it even shows you if the fraction is 'equal to', 'less than' or 'greater than' the original decimal number, more or less the same way the HP32SII does), but you would need the Extended Functions Module or a HP41CX to use it.

To use it on the 41C series:

X: %decimal_number -> Y: %numerator X: %denominator

Y: %decimal_number X: %precission -> Y: %numerator X: %denominator

the default precission is the number at the forth step (12). The code can be improved, I'm sure. If you find any mistake or do any improvement, please, let me know.

Greetings, Xose

#25

Hi!

I am interested in a ->Q prg for my HP15C, but I don't understand the 28S code. Can you tell me where to get the T.A & J.E.B 'Fract' prg or comment your prg so that I can (try to) write a prg for the 15C.

Thanx, Peter...


#26

I know almost nothing about programming a 15C, but since it uses the traditional keystroke method maybe the 'Fract' code for the HP-41C could be easy to adapt.

I've uploaded the 'Fract' source codes for HP-28S, HP-42S and HP-41C to my site, you'll find them here: http://www.geocities.com/xose_manuel2/calc/fract.html

I've tried to comment the 28S code (excuses for my english :), I hope it'll help you.

I found the original code at the Center for Computational Linguistics (ftp://ftp.ccl.kuleuven.ac.be/pub/hp28), but it's only for the 28S and uncommented.


#27

Hi!

Well, works fine (41C version) on the 15C. Some minor chnages required, FRC = FRAC, no STO 01 = STO 1 etc. XEQ 10 = GSB .0, LBL 10 = LBL .0 and some TEST X instead of x y etc. You could use recall and store arithmetic (RCL + 3...) but I didn't use it here.

Thanx, Peter

So it makes FRAC for HP15C:

01·LBL A 02 ENTER 03 FRAC 04 12 05 X Y 06 X=0 07 Rv 08 Rv 09 CHS 10 10^X 11 2 12 / 13 STO 1 14 Rv 15 STO 5 16 ENTER 17 ABS 18 STO 0 19 / 20 STO 4 21 1 22 STO 2 23 CLX 24 STO 3 25 RCL 0 26·LBL 0 27 RCL 0 28 RCL 2 29 * 30 ENTER 31 ENTER 32 2 33 1/X 34 + 35 GSB .0 36 - 37 ABS 38 RCL 1 39 RCL 2 40 * 41 TEST 7 42 GTO 1 43 Rv 44 Rv 45 1/X 46 ENTER 47 INT 48 ABS 49 RCL 2 50 * 51 RCL 3 52 + 53 RCL 2 54 STO 3 55 Rv 56 STO 2 57 Rv 58 FRAC 59 GTO 0 60·LBL 1 61 RCL 0 62 RCL 2 63 * 64 2 65 1/X 66 + 67 GSB .0 68 RCL 4 69 * 70 RCL 2 71 RTN 72·LBL .0 73 CHS 74 TEST 4 75 GTO 2 76 1 77 - 78·LBL 2 79 INT 80 CHS 81 RTN

#28

Some months ago I developed the little program enclosed below in order to convert a decimal diameter value into a diameter value expressed in inches and fractions of a inch (for CAD related purposes). The listing is self-explaining because the algorithm is very simple (sort of trial and error), moreover, it is easily translable into any HP calculator language. On a calculator however this algorithm can get slow in the case of irrational numbers and very low values for epsilon. There is an algorithm based on modular arithmetics that does the same calculation in a more efficient way, if I'm not wrong.

------------------------------------------------------------------------------

REM Fractions

DIM mnt, r, eps, delta AS DOUBLE

DIM i, j AS LONG

CLS

PRINT ""

INPUT "Mantissa "; mnt

neweps:

INPUT "Epsilon "; eps

i = 1

j = 1

iterate:

j = j + 1

r = i / j

delta = ABS(r - mnt)

IF delta mnt THEN

GOTO iterate

END IF

result:

PRINT ""

PRINT "Fraction = "; i; " / "; j; " ( "; r; " )"

PRINT "Error = "; 100 * delta / mnt; " %"

PRINT ""

choice$ = ""

INPUT "New epsilon (Y/N) "; choice$

choice$ = UCASE$(choice$)

IF choice$ = "Y" THEN

PRINT ""

GOTO neweps

END IF

SYSTEM

------------------------------------------------------------------------------


Possibly Related Threads...
Thread Author Replies Views Last Post
  Converting Great Circle Navigation from 41C to 42S Bill Triplett 11 1,166 11-13-2013, 07:24 AM
Last Post: Kimberly Thompson
  HP Prime: Converting number to Sci notation and back BruceTTT 1 379 11-12-2013, 02:11 AM
Last Post: Phil Wipf
  HP Prime program: rounding to a fraction Patrice 3 503 10-31-2013, 06:16 AM
Last Post: Joe Horn
  HP15c continued fraction for Ln(Gamma) Tom Grydeland 0 314 09-30-2013, 05:48 AM
Last Post: Tom Grydeland
  [wp34s] Converting to/from IEEE 754 Binary64 (Double Precision) David Maier 1 330 06-15-2013, 09:21 PM
Last Post: Paul Dale
  OT - Converting 9 track 6250 bpi tapes Marcel Samek 0 238 05-31-2013, 08:26 PM
Last Post: Marcel Samek
  Binary versus Decimal prefixes bill platt 22 1,545 04-27-2013, 11:22 AM
Last Post: Walter B
  Decimal/Binary Conversions for the HP 39gii - 3/16/2013 Eddie W. Shore 0 287 03-16-2013, 04:30 PM
Last Post: Eddie W. Shore
  33s Decimal Point Matt Agajanian 4 567 11-06-2012, 09:20 PM
Last Post: Matt Agajanian
  Obtaining More Decimal Digits (50g) Eddie W. Shore 3 489 09-13-2012, 05:38 PM
Last Post: Gilles Carpentier

Forum Jump: