I have tried to do this – Making any float value to int value. What I tried to achieve is make it 2.00-2.99 goes to 2.
Note: Im not trying to do Approximation (lower than 2.49 goes to 2, and those 2.50+ goes to 3).
I have done this so far
public int RemoveDecimal(float value)
{
string TempText = (string)value;
TempText.Remove(IndexOf('.'));
return int.parse(TempText);
}
But this will get an error when the float value ends with .00
How can I achieve this?
Thanks for any help
Math.Floor is the function you need.
It:
Example:
Or, you could simply cast to an integer – this will simply ignore the decimal portion, so long as the range of the
decimalis within the range of anint(otherwise you will get an exception):