# Setting display precision in InputField with Dynamic variable

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?

• 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 7 '16 at 9: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 7 '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 7 '16 at 14:41

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.