Numerical
Numerical
Numerical[ expr ] returns the approximate numerical value of an expression, optionally rounded to a number of decimals.
Usages
Numerical[ expr ]
Numerical[ expr ] calculates the decimal value of expr. Integers stay integers. If expr contains variables, only the numerical parts are calculated.
| Example | in | out |
|---|---|---|
The value of Pi. |
Numerical[ Pi ] |
3.14159265359 |
| An integer result. | Numerical[ 3^2 + 9 ] |
18 |
| A fraction with a finite decimal representation. | Numerical[ 1/4 ] |
0.25 |
| A script variable. | x := Sin[1] |
r = 0.841470984808 |
| Only the numerical part is calculated. | Numerical[ x + Pi ] |
x+3.14159265359 |
Numerical[ expr, n ]
Numerical[ expr, n ] rounds the value to n decimals. A negative n rounds to tens, hundreds, and so on. Halves are rounded up.
| Example | in | out |
|---|---|---|
Round to 3 decimals. |
x := Sin[1] |
r = 0.841 |
Round to 2 decimals. |
Numerical[ Pi, 2 ] |
3.14 |
0.25 rounded to 1 decimal. |
Numerical[ 1/4, 1 ] |
0.3 |
| Round to hundreds. | Numerical[ 1234.5678, -2 ] |
1200 |
| Round each element of a list. | Numerical[ {Pi, Sqrt[2]}, 2 ] |
{3.14, 1.41} |
Details
- Integers are not changed:
Numerical[ 2, 2 ]gives2, not2.00. - Trailing zeros are not displayed:
Numerical[ 1/4, 3 ]is displayed as . - Repeating decimals: without
n, a value such as1/3is calculated with 16 digits. Give a number of decimals to get a short result. Numerical[ NaN ]givesNaN.
See also: Round, Floor, Ceil, DecimalToFraction