Cleanest code for getting aspect ratio in JS (int to float)

Can’t just use

Screen.width / Screen.height

because they are ints.

Can it be done nicer than this?

System.Convert.ToSingle(Screen.width) / Screen.height
parseFloat(Screen.width) / Screen.height
(Screen.width + 0.0) / Screen.height

Well, shorter anyway…

–Eric

Those look more aesthetically pleasing to me. Any performance difference between any of these methods?

Presumably you’re only doing it once so it doesn’t matter, but if not, the performance drag from the division would probably overwhelm whatever differences there are.

–Eric

Well which one do you like, then? :slight_smile:

I’m not telling; it wouldn’t be fair to the others. :wink:

–Eric

Well I’m not as good a politician as you. :twisted: I like parseFloat because it keeps me from feeling the need to put a comment in.

There ya go. :slight_smile:

–Eric