HP Forums

Full Version: Rounding with units
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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?
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, 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]
Yes I didn’t notice but you have to suppress the unit before doing other calculations than +-/*


(20/6)*1_(km)▶AA ;
Hmm... i thought rounding and truncation supported units now. Or maybe that was DMS. I will check.

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)...

Reference URL's