I have an Interpretation Button that displays its label correctly on evaluation. However, when I copy and paste it as input the label loses its formatting.

Interpretation[{x = RandomReal[]}, Button[Dynamic[N[x, 6]], x = RandomReal[]], N[x, 6]]

Mathematica graphics

When this is copy and pasted into an input cell it changes to:

Mathematica graphics

How can I get it to retain its label formatting which should be the 6 decimal place number?

Also, I though N was cutting the number down to 6 significant figures. This is obviously not the case since the machine precision number is showing up in the label. What have I missed here, as well?

  • $\begingroup$ It's because an input cell displays the number input form, which is what you are seeing. $\endgroup$ – m_goldberg Dec 2 '16 at 1:52

It happens because "Input" cell style has NumberMarks -> True while "Output" inherits default False.

You can set BaseStyle -> NumberMarks -> False for the Button:

 {x = RandomReal[]}, 
 Button[Dynamic[N[x, 6]], x = RandomReal[], BaseStyle -> NumberMarks -> False], 
 N[x, 6]

As an option

Interpretation[{x = RandomReal[]}, Button[Dynamic@ToString@SetPrecision[x, 6], 
               x = RandomReal[]], N[x, 6]]


Interpretation[{x = RandomReal[]}, Button[Dynamic@N@Round[x, 1*^-6], 
               x = RandomReal[]], N@Round[x, 1*^-6]]

As far as I understand, N really doesn't change anything about a machine number, not even its precision, it does most of the work on exact inputs. So for machine numbers you need to use SetPrecision at the very least.


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.