Advertisement
Guest User

Untitled

a guest
Aug 22nd, 2014
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.41 KB | None | 0 0
  1.     void Start()
  2.     {
  3.         float x = 1.234567f;
  4.         Debug.Log(RoundTo(x, 5)); //prints 1.2347
  5.         Debug.Log(RoundTo(x, 3)); //prints 1.235
  6.         Debug.Log(RoundTo(x, 1)); //prints 1.2
  7.     }
  8.  
  9.  
  10.     float RoundTo(float numToRound, int numberOfDigits)
  11.     {
  12.         float powTen = Mathf.Pow(10, numberOfDigits);
  13.         numToRound *= powTen;
  14.         return Mathf.Round(numToRound) / powTen;
  15.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement