Post Reply 
How to round an HMS number?
01-01-2018, 04:53 PM
Post: #1
How to round an HMS number?
I'd like to know if it is posible to round the seconds in a number written in HMS format.

Here is an example. I'd like to round the number 15º16'16.99968" to 15º16'17". The function ROUND produces the following results:

ROUND(15º16'16.99968", 0) -> 15º00'00"
ROUND(15º16'16.99968", 1) -> 15º18'00"
ROUND(15º16'16.99968", 2) -> 15º16'12"
ROUND(15º16'16.99968", 3) -> 15º16'15.6"
ROUND(15º16'16.99968", 4) -> 15º16'17.04"

It seams that ROUND first converts 15º16'16.99968" to its decimal equivalent 15.2713888, then rounds this value to the specified number of decimal places (for example for 3 decimal places -> 15.271) and then converts this value back to the HMS format (15º16'15.6")

So, does anyone know how to get 15º16'17"?
Find all posts by this user
Quote this message in a reply
01-01-2018, 05:01 PM
Post: #2
RE: How to round an HMS number?
I don't know it this could help you, but I do as above in my program Effemeridi (Ephemeris) with angles:

Code:

trunc_angle(ang)
// trunc decimal from a DEG form angle
BEGIN
  →HMS((IP(HMS→(ang)*3600)/3600));
END;

simp_angle(ang)
BEGIN
  LOCAL angle;
  angle:=360*FP(ang/360);
  IF angle<0 THEN
  angle:=angle+360
  END;
  RETURN angle;
END;

HNY!

Salvo

∫aL√0mic (IT9CLU), HP Prime 50g 41CX 71b 42s 12C 15C - DM42 WP34s :: Prime Soft. Lib
Visit this user's website Find all posts by this user
Quote this message in a reply
01-01-2018, 05:58 PM
Post: #3
RE: How to round an HMS number?
(01-01-2018 05:01 PM)salvomic Wrote:  I don't know it this could help you, but I do as above in my program Effemeridi (Ephemeris) with angles:

Code:

trunc_angle(ang)
// trunc decimal from a DEG form angle
BEGIN
  →HMS((IP(HMS→(ang)*3600)/3600));
END;

simp_angle(ang)
BEGIN
  LOCAL angle;
  angle:=360*FP(ang/360);
  IF angle<0 THEN
  angle:=angle+360
  END;
  RETURN angle;
END;

HNY!

Salvo

Thanks Salvo! Your function applied to my case →HMS(IP(HMS→(15º16'16.99968")*3600)/3600) returns 15º16'16" - it truncates as its name suggests.

Inspired by your function I've found that →HMS(ROUND(HMS→(15º16'16.99968")*3600,0)/3600) returns 15º16'17" - the answer I was looking for.

HNY!
Find all posts by this user
Quote this message in a reply
01-01-2018, 05:59 PM
Post: #4
RE: How to round an HMS number?
(01-01-2018 05:58 PM)JMB Wrote:  Thanks Salvo! Your function applied to my case →HMS(IP(HMS→(15º16'16.99968")*3600)/3600) returns 15º16'16" - it truncates as its name suggests.

Inspired by your function I've found that →HMS(ROUND(HMS→(15º16'16.99968")*3600,0)/3600) returns 15º16'17" - the answer I was looking for.

HNY!

Happy! :-)

ciao

∫aL√0mic (IT9CLU), HP Prime 50g 41CX 71b 42s 12C 15C - DM42 WP34s :: Prime Soft. Lib
Visit this user's website Find all posts by this user
Quote this message in a reply
01-01-2018, 06:04 PM
Post: #5
RE: How to round an HMS number?
Hello,

Remember that unlike the 48 series of calculators, the HMS functions don't actually change the value underneath. Rather, they just set a flag to display/interpret the underlying value as a HMS input. This is why you can do things directly like SIN(<dms_number>), or + - * / and it will work directly without the need to do intermediate conversions like on the old system. It is much more convenient for every case EXCEPT the one you've found when you are trying to round a value like you are doing.

TW

Although I work for the HP calculator group, the views and opinions I post here are my own.
Find all posts by this user
Quote this message in a reply
01-01-2018, 06:15 PM
Post: #6
RE: How to round an HMS number?
Thanks for your explanation, Tim.
Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: 1 Guest(s)