Answers for "unity round float to decimal"

C#
8

round to float unity

float f = 3.16856f;
f = Mathf.Round(f * 10.0f) * 0.1f;
//Which will give 3.2f


//If you want 2 decimal points then,


float f = 3.16856f;
f = Mathf.Round(f * 100.0f) * 0.01f;
//Which results in 3.17f, and so on.
Posted by: Guest on July-25-2020
1

unity round to x decimals

using System;

int decimalPlaces = 4;
float number = 10.335577f;

Debug.Log(Math.Round(number, decimalPlaces));

//Output: 10.3356
Posted by: Guest on January-04-2022

Code answers related to "unity round float to decimal"

C# Answers by Framework

Browse Popular Code Answers by Language