1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Won't Fix SpinBox

Discussion in 'Resolved Bug Reports' started by Uniphix, Aug 27, 2013.

  1. Uniphix

    Uniphix Active Member

    When using spin box for floats such as 0.01 or something of this sort. It cannot go pass 0.03, and if you set it to 0.04 it will go up to 0.06 then 0.06999999999 and stop there again...

    this is using something like

    <input type="text" class="SpinBox" step="0.01" min="0.00" max="1.00" />
     
  2. Mike

    Mike XenForo Developer Staff Member

    We have run into this and it's the nature of floats - you'll see this come up in various languages. As such, our spin boxes are only "safe" with integers.
     
  3. Uniphix

    Uniphix Active Member

    That is kind of lame, when your adding 0.01 + 0.02 = 0.03
    when the step value is 0.01, its not a float issue it is a math issue... I can fix it locally on my end... The reason for this failure is because of this...

    Code:
    /**
            * Takes the value of the SpinBox input to the nearest step.
            *
            * @param string +/- Take the value up or down
            */
            stepValue: function(plusMinus)
            {
                var val = this.getValue(),
                    mod = val % this.parameters.step,
                    posStep = (plusMinus == '+'),
                    newVal = val - mod;
    
                if (!mod || (posStep && mod > 0) || (!posStep && mod < 0))
                {
                    newVal = newVal + this.parameters.step * (posStep ? 1 : -1);
                }
    
                this.$input.val(this.constrain(newVal));
                this.$input.triggerHandler('change');
            },
    When val is 0.03 the mod becomes 0.009999999999999998 so therefore the newVal = val - mod; = 0.02 when it should just remain at 0.03... so therefore it never goes pass 0.03 because it becomes newVal = 0.02 + step = 0.01 = 0.03
     

Share This Page