Saturday, September 15, 2018

HP 20S and HP 21S: Rounding Numbers

HP 20S and HP 21S:  Rounding Numbers

Introduction

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:  
http://edspi31415.blogspot.com/2018/08/hp-12c-platinum-and-dm-41l-rounding.html

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

Instructions

Enter x, press [INPUT], enter n (number of decimal places)

Examples

For these examples, I have set the calculator in ALL setting ( [right shift], [ ) ] )

Example 1:  Round π to 4 places.

π [ INPUT ] 4  [XEQ] (C)

Result:  3.1416

Example 2:  Round e^2.2 to 6 places

2.2 [e^x] [INPUT] 6 [XEQ] (C)

Result:  9.025013

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.  

Source:

Keith Oldham, Jan Myland, and Jerome Spanier  An Atlas of Functions Second Edition,  Springer.  2009 ISBN 978-0-387-48806-6

Eddie

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.