I\'m converting double to float using ye old float myFloat = (float)myDouble
.
This does however sometimes result in \"Infinity\", which is not good for
So if the value is greater than float.MaxValue
, are you happy for it to just be float.MaxValue
? That will effectively "clip" the values. If that's okay, it's reasonably easy:
float result = (float) input;
if (float.IsPositiveInfinity(result))
{
result = float.MaxValue;
} else if (float.IsNegativeInfinity(result))
{
result = float.MinValue;
}