Post Reply 
Rounding with units
11-09-2019, 02:40 AM
Post: #1
Rounding with units
Looks like the round function does not handle numbers with units. I guess because the number with units is really a string? When a round function is used on a value that has units and you try to print via the message box, the message box never appears. The only way I could get it to work is first divide out the units, round, and reapply the units.

Did I miss something?
Find all posts by this user
Quote this message in a reply
11-09-2019, 06:25 AM
Post: #2
RE: Rounding with units
Although it fails in Home, it works in CAS, so a workaround in Home and non-CAS programs is to use either of these syntaxes:

CAS.round(unit)
CAS.round(unit, places)

Only positive values for "places" seem to work. The usual option of using a negative value for "places" (to specify significant digits) does not seem to work. Values greater than 14 for "places" sometimes yield bizarre results (gotta be a bug).

[Image: round-units.png]

<0|ɸ|0>
-Joe-
Visit this user's website Find all posts by this user
Quote this message in a reply
11-09-2019, 06:33 AM
Post: #3
RE: Rounding with units
Yes I didn’t notice but you have to suppress the unit before doing other calculations than +-/*

Code:

(20/6)*1_(km)▶AA ;
ROUND(UVAL(AA),-3)*UPART(AA)▶AA ;
MSGBOX(AA) ;
Find all posts by this user
Quote this message in a reply
11-09-2019, 12:02 PM
Post: #4
RE: Rounding with units
Hmm... i thought rounding and truncation supported units now. Or maybe that was DMS. I will check.

TW

Although I work for HP, the views and opinions I post here are my own.
Find all posts by this user
Quote this message in a reply
11-12-2019, 06:17 AM
Post: #5
RE: Rounding with units
Hello,

Sorry, nor unit support for Round (and Trunc, they are the same function)... I will look at what it would take to add it...

Units are NOT strings... Units are an object (ie, a pointer to our generic object type, it could actually, tehcnically be anything)... and a list of triplets...
Each triplet (3 bytes) is a multiplicator or factor (as in k, m, G...) saved as a signed 8 bit number, normally a multiple of 3, an index in our unit list and a signed byte for the power (which is why unit powers are limited to 127)...

Cyrille

Although I work for the HP calculator group, the views and opinions I post here are my own. I do not speak for HP.
Find all posts by this user
Quote this message in a reply
Post Reply 




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