4
$\begingroup$

This question already has an answer here:

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$

marked as duplicate by Mr.Wizard Jul 10 '16 at 23:52

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

7
$\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$
  • $\begingroup$ Of course PrintPrecision can also be set programmatically: SetOptions[EvaluationNotebook[], PrintPrecision -> 10]. $\endgroup$ – Alexey Popkov Aug 24 '15 at 13:28

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