3

I have a following code:

Manipulate[
    Column@{
       InputField[Dynamic[coefA], Number, ImageSize-> 130]
       (*InputField[Dynamic[SetPrecision[coefA,3]], Number, ImageSize->130]*), 
       Slider[Dynamic[coefA], {-10., 10., .01}, ImageSize -> 130]
    },
    {{coefA, 0}, ControlType -> None}, 
    AppearanceElements -> None]

I want both Slider and InputField to be able to modify coefA variable, however I would like to have a special formatting inside InputField - to 2 decimal points (like: 1.2358->1.24). The commented line works... for the Slider. It can modify variable and it is printed correctly, but I loose ability to modify it via InputField because:

"Tag SetPrecision in SetPrecision[-1.74,3] is Protected."

Any ideas how it can be done?

Kuba
  • 136,707
  • 13
  • 279
  • 740
michelson
  • 443
  • 2
  • 7
  • 1
    Is this enough? Dynamic[SetPrecision[coefA, 3], (coefA = #) &] – Kuba Dec 18 '15 at 12:22
  • This is closely related topic: 6259 but solutions from there are not working with Number type InputField. – Kuba Dec 18 '15 at 12:26
  • I've noticed that you haven't accepted any of answers to you questions. Are they missing something. Please, take a tour. – Kuba Jan 07 '16 at 09:56
  • Oh I'm sorry i totally forgot I asked this question here! You suggested the same solution as my teacher so i totally forgot to thank you - Thanks, @Kuba. Im gonna mark this as '[SOLVED]' now (how to do so...? :D) – michelson Jan 07 '16 at 14:39
  • No worries, I just wanted to tell you about the accept mark because sometimes users are not aware of it. – Kuba Jan 07 '16 at 14:41
  • About how to do so, take a look at the link 'tour' I gave in the previous comment. – Kuba Jan 08 '16 at 09:31
  • @michelson You can marked this question, and any other of your questions, as SOLVED by clicking the checkmark sign. I noticed none of your question have accepted answer. Also, in case you don't know, when you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. – Michael E2 Mar 10 '16 at 12:31

1 Answers1

3

So, you can use very general answer from Michael E2 (the bottom of his answer) or this quick fix:

Column@{
    InputField[Dynamic[SetPrecision[coefA, 3], (coefA = #) &], Number], 
    Slider[Dynamic[coefA], {-10., 10., .01}]
}

Keep in mind that precision is not closely related to number of digits after decimal point.

To have 10.12 and 1.23 at once you have to use NumberForm[var, {Infinity, 2}] and approach from linked answer.

Kuba
  • 136,707
  • 13
  • 279
  • 740