I have the following code in my controller:
private void setProgress(float value)
{
progress = (float)Math.Round(value,4);
}
But when value is something like the numbers in the title (a number very close to an int) it doesn’t work and progress just gets the original value.
Why is this happening?
Because 1 and 24 may not represented exactly using binary floating-point numbers, depending on how those numbers were calculated. If you need a true integer, round it then convert it to an int:
if you need to compare a float to an int (even a constant one, then compare the difference to some very small number:
If you need to display it as if it were an integer, display it with 0 decimal places: