cancel
Honor Student
2 0 0 0
Message 1 of 3
423
Flag Post
HP Recommended

Solved!

# How can I display a fraction from a decimal in a HP program ?

HP Prime la V2

I am making a program that take a,b and c and does the quadratic formula, but I can’t make it show me the answers in fraction form. The only way I can tell is to press the a/bc button but that does not work in a program. Any Help is appreciated!

Andr3w

Tags (5)
2 REPLIES 2
PhD Student
504 488 79 144
Message 2 of 3
381
Flag Post
HP Recommended

Solved!

## How can I display a fraction from a decimal in a HP program ?

Here are three radically different ways to program the Prime to display a result as a fraction.  Use whichever one serves your needs best.

(1) Use the QPI function, which was added to Prime's command set not long ago, so if your Prime doesn't have it in the Toolbox Catalog, be sure to upgrade your Prime to the latest firmware.  As its Help screen says, QPI converts its input to either a simple fraction or a simple expression such as a square root, log, multiple of pi, and so on.  Try QPI(1.25) to see it in action.  See its Help screen for more details, such as how to control its accuracy.

(2) Use the STRING function, which lets you specify that you want the output to be expressed as a fraction.  Warning: You must type STRING in uppercase letters, or it won't work as desired. Example: STRING(pi,8,4) outputs "201/64". The 8 in this example specifies using Standard display mode; using 15 there would output the fraction as a mixed number. The 4 in this example specifies the desired accuracy. See the Help screen for STRING for more information about its many options.  It can be a bit confusing at first, so if you get stumped, please don't hesitate to follow up here with further questions.

(3) Use the exact() function, which must be typed in lowercase letters or it won't work at all.  exact(1.25) returns 5/4. Its precision is controlled by the value of epsilon in the CAS Settings (page 2). See the Help screen for exact for more details.

EDIT: Sorry, I just noticed that you mentioned that your values are outputs from the quadratic formula. In that case, you can avoid all of the above by writing your program as a CAS program, because CAS programs can keep all values in exact form throughout the entire calculation, and therefore output them exactly, as simplified algebraic expressions.  If you are not familiar with writing CAS programs, just reply with a listing of your current program, and I'll show you how to rewrite it as an exact CAS program (unless somebody else here beats me to it).  CAS programming is really cool.

Hope this helps! Disclaimer: I don't work for HP. I'm just an HP calculator fanatic.

-Joe-
Tags (1)
PhD Student
504 488 79 144
Message 3 of 3
354
Flag Post
HP Recommended

Solved!

## How can I display a fraction from a decimal in a HP program ?

Hey, I found a way to see the exact answers in fraction form without any need to write a program.  Just use this command in CAS view:

csolve(poly2symb( { a, b, c } )=0 )

substituting a, b, and c for the coefficients of your quadratic equation.  Example: to solve 3x^2 +4x -5 = 0, type this:

csolve(poly2symb( {3, 4, -5} )=0 )

This returns both solutions as exact algebraic expressions.  If the results are not automatically simplified, you can tap the [simplify] softkey to simplify the results.  If you'd rather have the results automatically simplified, change the CAS Setting of Simplify to Maximum.

Note: To obtain exact results, the coefficients that you specify must also be exact, so be sure not to include a decimal point anywhere in them.  They may be fractions or other algebraic expressions... just avoid using any decimal points.

If any readers here know of an even easier way to see the exact solutions of quadratic equations, please share it with us. Thanks!

-Joe-
† The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation