Skip to content
This repository has been archived by the owner on Aug 22, 2021. It is now read-only.

24 counts up to 23 and previously posted solutions don't work. #75

Open
temkaes opened this issue Jun 4, 2020 · 2 comments
Open

24 counts up to 23 and previously posted solutions don't work. #75

temkaes opened this issue Jun 4, 2020 · 2 comments

Comments

@temkaes
Copy link

temkaes commented Jun 4, 2020

24.0 works, 23 works and 25 works but 24 gets stuck at 23. Interestingly, the same issue can be replicated at 3, 6, 12, 24, 48 and 96...

I tried a few of the earlier posted solutions but still doesn't work.

@fastcatch
Copy link

fastcatch commented Oct 19, 2020

The problem is that first num is divided by divisions and only then multiplied by i. Javascript calculates with floats and thus rounds in sometimes unexpected ways. Change the order (first multiply, then divide) and it's gonna be allright. (Or round the result before parseInting.)

@gabrieljenik
Copy link

gabrieljenik commented Jun 11, 2021

My fix...

               // For first iteration, don't divide.
                var auxNum = i == divisions ? num : num / divisions * i;

then...

                // Preserve as int if input was int
                var newNum = parseInt(auxNum);

                // Preserve float if input was float
                if (isFloat) {
                    newNum = parseFloat(auxNum).toFixed(decimalPlaces);
                }

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants