6
$\begingroup$

As specified in documentation center the functions AccountingForm, NumberForm, etc. are useful only to display numbers in different notations: acts as a "wrapper", which affects printing, but not evaluation. But if I want to calculate with less digits how can I do?

For example:

 n1 = 0.2345;
 n2 = 1;
 n2 - n1
0.7655
n11 = NumberForm[n1, 3];
n2 - n11
1-0.235.

EDIT:

Perhaps, sure, I explained not very well my problem. I want that only n1 has 3 decimal. If I use

 NumberForm[{n1, n2 - n1}, 3] 

first I consider all the number with all digits, and then I cut the decimals. I'm I wrong? I'm doing an analysis about how many digits I need in a calculation. All the other number must have 4 digits and only one three digits, so I want to force that number to have three digits

$\endgroup$
2
  • 1
    $\begingroup$ Round[number,0.001]?? $\endgroup$ Commented Aug 24, 2015 at 15:50
  • $\begingroup$ See also: (3098), (55292) $\endgroup$
    – Mr.Wizard
    Commented Jul 10, 2016 at 23:41

1 Answer 1

8
$\begingroup$

The documentation is misleading in this case. The wrapper NumberForm is not transparent to numerical calculation -- it stops it dead. This means you should only apply it to your final calculations when all the numerical work is done. So the following works.

NumberForm[{n1, n2 - n1}, 3]
{0.235, 0.766}

If what you want is for all the numerical work in a notebook to displayed at less than six figures you can change this default value in the Mathematica Preferences dialog or with the Options Inspector.

In Preferences look for 'Displayed precision' in the Appearance > Numbers > Formatting panel.

In the Option Inspector search on PrintPrecision.

When the change in displayed precision is made in Preferences, it affects every notebook. In the Options Inspector you can confine the change to the current notebook if you so wish.

$\endgroup$
1
  • $\begingroup$ Of course PrintPrecision can also be set programmatically: SetOptions[EvaluationNotebook[], PrintPrecision -> 10]. $\endgroup$ Commented Aug 24, 2015 at 13:28

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