2

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?

m_goldberg
  • 107,779
  • 16
  • 103
  • 257
Timitry
  • 121
  • 2
  • 3
    Take a look at these questions and see if the answers to them answer your question: 4685, 6259 – Michael E2 Feb 05 '15 at 17:22
  • 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! – Timitry Feb 05 '15 at 17:52
  • 1
    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]. – Michael E2 Feb 05 '15 at 21:17

0 Answers0