The community needs to determine if this is behavior is a bug or not. – Mr.Wizard
Consider the following InputField
InputField[Dynamic[h2,
If[# === Null, h2 = h2, h2 = Round[#, 0.001]] &], Number]
The purpose of the second argument of Dynamic is to avoid someone entering a value with more than 3 decimal places (or emptying the field after some value has been assigned).
For example, entering 0.4691 immediately reassigns the InputField
to 0.469.
The problem is that entering the number 0.468 renders 0.4680000000000001. I imagine it’s something to do with the representation of 0.468 in binary, etc.
How can I avoid this after rounding action?
EDIT:
After some more testings, I see that it is the Number
part that is causing the problem.
This works "badly":
InputField[Dynamic[h2], Number]
This works OK:
InputField[Dynamic[h2]]
If you do Do[h2 = i; Pause[0.1], {i, 0.04, 0.08, 0.001}]
, you can get a good picture of the problem:
How can I avoid this Number
side effect?