The following program will allow the user to round any positive number to any number of decimal places, regardless of fixed decimal settings.
This is based off the algorithm:
x_rounded = int(10^n * x + 0.5) ÷ 10^n
Note: You can check out the programs for the HP 12C and DM 41L/HP 41C here:
HP 20S and HP21S Program: Rounding Numbers
Key codes for both calculators are the same.
Step Key Key Code
01 LBL C 61, 41, C
02 10^x 51, 12
03 STO 0 21, 0
04 SWAP 51, 31
05 × 55
06 RCL 0 22, 0
07 + 75
08 . 73
09 5 5
10 = 74
11 IP 51, 45
12 ÷ 45
13 RCL 0 22, 0
14 = 74
15 RTN 61, 26
Enter x, press [INPUT], enter n (number of decimal places)
For these examples, I have set the calculator in ALL setting ( [right shift], [ ) ] )
Example 1: Round π to 4 places.
π [ INPUT ] 4 [XEQ] (C)
Example 2: Round e^2.2 to 6 places
2.2 [e^x] [INPUT] 6 [XEQ] (C)
Note: I typed this blog entry by using the Jarte word processor (http://www.jarte.com/index.html). I am using the free version for the first time (there is also a paid version). Jarte is based off of WordPad, but adds spell check and nicer editing features.
Keith Oldham, Jan Myland, and Jerome Spanier An Atlas of Functions Second Edition, Springer. 2009 ISBN 978-0-387-48806-6
All original content copyright, © 2011-2018. Edward Shore. Unauthorized use and/or unauthorized distribution for commercial purposes without express and written permission from the author is strictly prohibited. This blog entry may be distributed for noncommercial purposes, provided that full credit is given to the author. Please contact the author if you have questions.