3

I need Mathematica to remember only things upto two decimal places.

I'm currently using the unwieldy Floor[x*100]/100 which works but is there a better way to make it use two decimal places (throughout the notebook is okay).

I tried N[x,{2,2}] but although it displays the requisite two decimal places, I know that the kernel still remembers. For instance, if I try it for N[1.234,{2,2}]-1.23 is not 0. It is in fact 0.004. How can I get rid of this?

xyz
  • 605
  • 4
  • 38
  • 117
user1936752
  • 259
  • 2
  • 7
  • Examine FullForm@N[1.234, {2, 2}] and you'll see it's not doing what you think it is doing. Try instead SetAccuracy[1.234, 2] - 1.23``2. One problem using this approach is that Mathematica tracks relative precision, not a fixed number number of decimal places. Do you want fixed-point arithmetic or is just about output formatting? – Michael E2 Nov 03 '15 at 11:24

2 Answers2

2

To make your function work "throughout the workbook" you can use:

$PrePrint = N @ Floor[#*100]/100 &;

Now

 {1.23999, Pi}

{1.23, 3.14}

Restore $PrePrint to the default:

$PrePrint =.
eldo
  • 67,911
  • 5
  • 60
  • 168
2

You want Round[] for this:

Round[1.234, 1.*^-2] - 1.23
   0.

This can be used with $PrePrint if needed.

J. M.'s missing motivation
  • 124,525
  • 11
  • 401
  • 574