I want to control a value in my program either by a Slider or an InputField. The following code does what I want in principle:

Row[{"Some value", Slider[Dynamic[value], {0, 2, 0.1}], 
InputField[Dynamic[value], Number, ImageSize -> 40]}]

When moving the slider, the value should only change in steps of 0.1. However, for some values, the following happens:

enter image description here

I guess that this is due to machine precision errors or something similar. I don't really care if the value is that little greater than 0.7, that won't disturb my calculations. However, I would like the InputField to only show one decimal digit. What would be the easiest way to do that?

  • 3
    $\begingroup$ Take a look at these questions and see if the answers to them answer your question: 4685, 6259 $\endgroup$
    – Michael E2
    Commented Feb 5, 2015 at 17:22
  • $\begingroup$ They helped me insofar that i recognized the number-attribute to be the problem. I just leave that out now and the problem is gone. It's not the best solution, since I only want numbers as input, but I can live with it! $\endgroup$
    – Timitry
    Commented Feb 5, 2015 at 17:52
  • 1
    $\begingroup$ Hi Timitry, I added an answer to question 4685. It should work for your case, too. E.g., InputField[Dynamic[If[value == 0, 0., SetAccuracy[value, 2]], (value = #) &], Number, ImageSize -> 40]. $\endgroup$
    – Michael E2
    Commented Feb 5, 2015 at 21:17


Browse other questions tagged or ask your own question.