Message Boards Message Boards

0
|
4701 Views
|
2 Replies
|
4 Total Likes
View groups...
Share
Share this post:

Turning off significant digits?

Posted 5 years ago

Hello, hopefully a simple question, but I'm simply trying to take the difference:

29204.24-5840.85

The result of which is 23363.4, which is obviously wrong. I assume it is mathematica paying attention to signficant digits or something of the sort, but if I calculate

9204.24-840.85

I get 8363.39 which is now correct. So I'm totally puzzled. What I find ironic is the example I find trying to search support of 2^100 for which mathematica gives an exact answer (1267650600228229401496703205376). There is a very easy, quite short and neat exact answer for 29204.24-5840.85, that answer is 23363.39. So why is mathematica rounding up, or playing at significant digits? And how can I turn this off for number that have nice clean calculations associated with them?

POSTED BY: Tyler Corbett
2 Replies

By default, the Mathematica Front End displays 6 digits of numbers with finite precision. It is internally using more digits for the calculations, but it only displays 6, rounding the final digit if necessary.

You can changed this by going to File>Preferences (Mathematica>Preferences on a Mac), choosing the Appearance tab, the Numbers subtab, and then the Formatting sub-subtab. A bit over halfway down, there is an option for "Number of digits displayed in output". Change this to something greater than 6. You will then see your desired result in the Front End.

You can use functions like NumberForm to change how numbers are displayed on a case by case basis, if needed.

POSTED BY: Karl Isensee

Default number of decimal digits displayed is six. There are many ways to display more, for example:

NumberForm[29204.24 - 5840.85, 7]

yields

23363.39

Approximate numbers (anything with a decimal point) use an internal binary representation. This means that internally, approximate decimal inputs are rounded to the nearest binary floating point number, so results may not exactly reflect an exact decimal calculation. For exact calculation, use rational numbers:

2920424/100 - 584085/100

yields

2336339/100
POSTED BY: John Doty
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract