How to round an HMS number? [SOLVED] - Printable Version +- HP Forums (https://www.hpmuseum.org/forum) +-- Forum: HP Calculators (and very old HP Computers) (/forum-3.html) +--- Forum: HP Prime (/forum-5.html) +--- Thread: How to round an HMS number? [SOLVED] (/thread-9829.html) |
How to round an HMS number? [SOLVED] - JMB - 01-01-2018 04:53 PM 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"? RE: How to round an HMS number? - salvomic - 01-01-2018 05:01 PM I don't know it this could help you, but I do as above in my program Effemeridi (Ephemeris) with angles: Code:
HNY! Salvo RE: How to round an HMS number? - JMB - 01-01-2018 05:58 PM (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: 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! RE: How to round an HMS number? - salvomic - 01-01-2018 05:59 PM (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. Happy! :-) ciao RE: How to round an HMS number? - Tim Wessman - 01-01-2018 06:04 PM 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. RE: How to round an HMS number? - JMB - 01-01-2018 06:15 PM Thanks for your explanation, Tim. RE: How to round an HMS number? [SOLVED] - JMB - 07-21-2018 10:02 AM With the new firmware version 2.0.0.13865 (2018 07 06), the behavior of ROUND (and also TRUNC) has been changed. Now using 0, 2 and 4 as the second argument, you can round to the nearest degree, minute or second. The function ROUND produces now the following results: ROUND(15º16'16.99968", 0) -> 15º00'00" ROUND(15º16'16.99968", 2) -> 15º16'00" ROUND(15º16'16.99968", 4) -> 15º16'17" RE: How to round an HMS number? [SOLVED] - Tim Wessman - 07-21-2018 12:44 PM Also handles sig figs since a negative value into ROUND/TRUNC does total sigits, not after the dot. Yes, this thread was the spur to get that changed. |