unity round up to nearest float code example

Example 1: 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.

Example 2: unity round float to nearest 100

//int
int sayi;
int = ((int)(((int)(sayi/100))*100));
//float
float sayi;
sayi = ((float)(((int)(sayi/100))*100));
///////////////////////////////////////////////


//int
int yuvarlama;
int sayi;
int = ((int)(((int)(sayi/yuvarlama))*yuvarlama));
//float
float yuvarlama;
float sayi;
sayi = ((float)(((int)(sayi/yuvarlama))*yuvarlama));