Rounding with units

11092019, 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? 

11092019, 06:25 AM
Post: #2




RE: Rounding with units
Although it fails in Home, it works in CAS, so a workaround in Home and nonCAS 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). <0ɸ0> Joe 

11092019, 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:


11092019, 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. 

11122019, 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. 

« Next Oldest  Next Newest »

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