Group Abstract Group Abstract

Message Boards Message Boards

0
|
2.2K Views
|
2 Replies
|
1 Total Like
View groups...
Share
Share this post:
GROUPS:

How to change precision of a Quantity

Posted 10 years ago

Whats the best way to change precision of a Quantity ? For example, to round this Quantity

Quantity[2.567786, "Hours"]

I tried

%~N~1

as well as approaches using ReplacePart and MapAt (part 1), but to no avail. Attributes@Quantity show it is {HoldRest, NHoldRest, Protected, ReadProtected}, which should allow operations on the first argument (i.e the magnitude 2.567786). I'm using v10.0.2

EDIT: I figured out that I need the NumberForm function. For example

Quantity[2.1234567, "Hours"]~NumberForm~3

evaluates to 2.12 h

POSTED BY: B C
2 Replies

You can also consider SetPrecision:

SetPrecision[Quantity[2.567786, "Hours"], 2]

which we can use in calculations. NumberForm is meant only for final formatted output.

POSTED BY: Gianluca Gorni
Posted 10 years ago

Thanks, +1 !

POSTED BY: B C
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard