Hi I’m a beginner so I don’t know how but how to you round doubles? So if like the double is 3.82372 it should round to 4 or if it’s 2.38194 it’ll round to 2
Math.Floor to round down.
Math.Round for general double-based rounding, where you can specify the midpoint rounding type.
System math class deals with doubles. I wouldn’t use
Mathf unless you are using floats (which you generally should be using unless you have a very good reason to use doubles).
Your best bet is to use Unity’s
Mathf library. For example:
myDouble = 3.82372;
myDoubleRounded = Mathf.Round((float)myDouble);
You’ll notice I cast the double to a float, and that’s because most of the methods of
Mathf utilize floats only. Unless you have a specific reason to use doubles in your project, it’s generally best to use floats.
Hi thank you it worked! But is there a way so it only rounds down?