- Home /
Math Round?
Is there a function to round a int to the nearest multiple of 2.75?
Nothing built in. Sounds more of a $$anonymous$$ath problem to me than a Unity issue. What have you tried to make this work?
Answer by Jamora · Aug 27, 2013 at 07:44 PM
While this is more of a math problem than a Unity one, the way you can do it is as follows:
public float RoundToNearestMultiple(float numberToRound, float multipleOf){
int multiple = Mathf.RoundToInt(numberToRound/multipleOf);
return multiple*multipleOf;
}
UnityScript really isn't that different from C#, come to think of it, it is actually less clear to read with all those colons. This answer will tell you how to translate between C# and UnityScript.
I'm using JavaScript, not C# so I can't really understand what you wrote. :(
Your answer
Follow this Question
Related Questions
Math.round not work 1 Answer
Is it possible to round down 0.99 to 0? 2 Answers
Rounding to multiples of 0.5 1 Answer
Float to Int 4 Answers
How can I round a number? 2 Answers