- Home /
How do i divide int by float?
Sorry if this is basic programming but theres still a few basics I'm not familiar with.
I'm trying to divide screen resolution by 1.5
Screen.SetResolution(Screen.width / 1.5f, Screen.height / 1.5f, true);
Argument 1: cannot convert from 'float' to 'int'
I've done
Screen.SetResolution(Screen.width * 10 / 15, Screen.height * 10 / 15, true);
Not sure if that's a good way of doing it or not.
Answer by sacredgeometry · Aug 09, 2019 at 10:12 PM
You would need to cast it to the type you want and then back i.e.
(int)((float)Screen.width/ 1.5f)
although in c# there is implicit casting on numeric types so
(int)(Screen.width/ 1.5f)
Should work too.
Edit: Sorry doing too much swift lately
Still saying the same thing with
Screen.SetResolution((float)Screen.width / 1.5f, (float)Screen.height / 1.5f, true);
(251,26): error CS1503: Argument 1: cannot convert from 'float' to 'int'
You didnt copy my example.
That casts the Screen.Width to a float but the $$anonymous$$ethod takes an int parameter so you need to give it an int.
Try copying and pasting either of my examples or copy the formatting. Notice where the parenthesis are.
You must have edited as it didn't update when i read it first :) ill give that a try thanks! [edit] Yep that did the trick thanks!
Your answer
Follow this Question
Related Questions
Distribute terrain in zones 3 Answers
Need decimals of a division of Ints 3 Answers
How do I sort floats by highest to lowest value? 1 Answer
4.6 Slider round to int? 1 Answer
Can I create a list with an int/float and a string? C# 2 Answers