how to normalize a range of values to 0 1 range

Hi i need to know how can i achiveve a normalize for ranged values for example

i have range 2304 to 0

and i want to know 1743 value in the range of 0 to 1

float normal = 1743 / 2304;

I can never remember if you need to cast ints to floats in operations like this so probably safer to to avoid decimals being truncated in the division of ints.

float normal = (float)1743 / (float)2304;

or for short

float normal = 1743f / 2304f;

Can someone clarify this?

1 Like

Mathf.InverseLerp is what you want:

Mathf.InverseLerp(0, 2304, 1743)
4 Likes

Yeah i guess this is better as it deals with values beyond the range.

1 Like

thanks very much