Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

toFixed converts x and y coordinates to strings #28

Open
puckey opened this issue Apr 7, 2016 · 4 comments
Open

toFixed converts x and y coordinates to strings #28

puckey opened this issue Apr 7, 2016 · 4 comments

Comments

@puckey
Copy link

puckey commented Apr 7, 2016

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

@supercrabtree
Copy link
Collaborator

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.

@puckey
Copy link
Author

puckey commented Apr 21, 2016

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"

@supercrabtree
Copy link
Collaborator

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?

@puckey
Copy link
Author

puckey commented Apr 21, 2016

Sounds perfect!

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

No branches or pull requests

2 participants