|
How do I take a float: x, and round it to the nearest .5? So if x is 5.1324 it would round to 5. But if x is 5.4216 it would round to 5.5 etc.
(comments are locked)
|
While Graham's answer is perfect in it's simplicity, this caught my attention... Would you mind to explain what this does? googeling this, I've come to believe the (float) is type-casting in c#?? can you do this in js with 'as float'? (or am I mixing things up here?) Some more research told me, this is not misspelled Mathf.Round but it's System.Math.Round ((thanks for making me look into the .net documentation... so far I've kept shying away from it :p )) Greetz, Ky.
Aug 05 '11 at 07:46 PM
SisterKy
Hi Ky, the difference between Math.Round and Math.Round with the MidpointRounding.AwayFromZero enumeration is that when AwayFromZero is specified, and the number is halfway between two other numbers, it is rounded toward the nearest number that is away from zero, instead of being rounded to a zero.
Aug 05 '11 at 07:58 PM
Meltdown
Uhm... not the difference between Math.Round and Math.Round with MidpointRounding but Mathf.Round and Math.Round with MindpointRounding... Weird!! For some reason I don't get e-mail notification if you answer me?! Almost missed your comment about html-tags (you really didn't see it formatted? What browser are you using? this worries me; thought the tags were foolproof...) and if I hadn't checked back here wouldn't have known about it... :( Are you getting notifications about me? Greetz, Ky.
Aug 05 '11 at 09:21 PM
SisterKy
(comments are locked)
|
|
multiply it by 2, round, then divide by 2???
(comments are locked)
|
