Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void Start()
- {
- float x = 1.234567f;
- Debug.Log(RoundTo(x, 5)); //prints 1.2347
- Debug.Log(RoundTo(x, 3)); //prints 1.235
- Debug.Log(RoundTo(x, 1)); //prints 1.2
- }
- float RoundTo(float numToRound, int numberOfDigits)
- {
- float powTen = Mathf.Pow(10, numberOfDigits);
- numToRound *= powTen;
- return Mathf.Round(numToRound) / powTen;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement