Approximate

Approximate

Approximate[ expr, n ] rounds a numerical value to n decimals, and keeps track of the rounding.

Usages

Approximate[ expr, n ]

Approximate[ expr, n ] calculates the value of expr and rounds it to n decimals. The result is a PrecisionConstant: a number that remembers its precision. Later calculations use the exact value, and when an answer is checked, any value that rounds to the same number matches. Use Numerical instead if you only need a decimal number.

Example in displayed
π to 2 decimals. Approximate[ Pi, 2 ] 3.143.14
A fraction. Approximate[ 1/3, 2 ] 0.330.33
An expression with a numerical value. Approximate[ 2*Pi + 1, 2 ] 7.287.28
Halves are rounded up. Approximate[ 2.45, 1 ] 2.52.5
Each element of a list. Approximate[ {Pi, EulerE}, 2 ] {3.14,2.72}\{3.14, 2.72\}

Approximate[ expr ]

Without n, the value is calculated as a decimal number, as with Numerical.

Example in out
The value of π. Approximate[ Pi ] 3.14159265359
Options

RoundingMode

How to round: 'Default' (halves up), 'Floor' (always down) or 'Ceil' (always up).

Syntax Example displayed
Approximate[ expr, n, RoundingMode=>'Floor' ] Approximate[ 2.45, 1, RoundingMode=>'Floor' ] 2.42.4
Approximate[ expr, n, RoundingMode=>'Ceil' ] Approximate[ 2.41, 1, RoundingMode=>'Ceil' ] 2.52.5

OmitTrailingZeroes

If set to False, the result is displayed with exactly n decimals. Default: True.

Syntax Example displayed
Approximate[ expr, n, OmitTrailingZeroes=>False ] Approximate[ 2.5, 3, OmitTrailingZeroes=>False ] 2.5002.500

RoundInteger

If set to True, integers are also given a precision. Default: False, so integers are not changed: Approximate[ 2, 1 ] gives 2.

Syntax Example displayed
Approximate[ expr, n, RoundInteger=>True ] Approximate[ 2, 1, RoundInteger=>True ] 2.02.0
Details
  • Variables: an expression with variables is not changed: Approximate[ x + Pi, 2 ] gives x+Pi. Use Numerical[ x + Pi, 2 ] to round the numbers in it.
Invalid input Result
Approximate[ 2.45, 1, RoundingMode=>'Up' ] Error: Invalid value for RoundingMode: 'Up'

See also: PrecisionConstant, Numerical, Round, Precision