victor icon indicating copy to clipboard operation
victor copied to clipboard

toFixed converts x and y coordinates to strings

Open puckey opened this issue 9 years ago • 4 comments
trafficstars

Since Victor#toFixed() uses Number#toFixed() under the hood, it is turning the x and y coordinates of the vector into strings: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toFixed

puckey avatar Apr 07 '16 09:04 puckey

Although you are correct, I would argue that it makes sense to keep the API consistent with the JavaScript one. I agree that Number#toFixed is kind of annoying, but when I call it I expect a string.

supercrabtree avatar Apr 21 '16 08:04 supercrabtree

The problem is that it will break all further functionality of the vector/point, since all other functions are expecting numbers, not strings.

If you want to follow Number#toFixed() you should return a new object, since Number#toFixed() does not change the object itself - it returns a new string.

var a = 10; var b = a.toFixed();

a is still a number.. b is "10"

puckey avatar Apr 21 '16 09:04 puckey

Good point. How do you feel about keeping #toFixed as returning a string (and change it to stop it mutating). And then adding a #roundToDecimalPlaces (or similar) method to allow for the functionality that you want?

supercrabtree avatar Apr 21 '16 09:04 supercrabtree

Sounds perfect!

puckey avatar Apr 21 '16 11:04 puckey