2
$\begingroup$

I have some random number x. It can be 222.1245646 or 3.141562652. How should I show this number to 5 decimal numbers ? I cant use this:

N[x, 5] because it shows 5 digits(222.12 or 3.1415).

$\endgroup$
2
$\begingroup$

Use NumberForm[].

This will display number 1.2345678 with 3 precise digits and 4 digits to the right of the decimal:

NumberForm[1.2345678, {3, 4}]

1.2300

You can adjust the second argument to suit your needs. Maybe like this:

NumberForm[1.2345678, {99, 5}]

1.23457

7 is at the end instead of 6 because of rounding.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.