#The 67% problem

1 messages · Page 1 of 1 (latest)

brittle thistle
brittle thistle
#

it's simply
Percent = (k/max); basically. both k and max are floats

reef acorn
#

Note that it is against our rules to make threads that auto-archive above 24hrs. So don't do that in future thanks

pallid venture
#

this thread title. so political

brittle thistle
#

Oh, I actually didn't know that.

#

my bad

pallid venture
#

but seriously, if you are adding +1 to a float that's at the end of its significant digit accuracy it will floor

#
public class FloatExample : MonoBehaviour
{
    const float max = 25000000;
    [Range(0,max)]
    public float k;

    [Range(0,100)]
    public float percentage;

    private void OnValidate()
    {
        percentage = (k / max) * 100;
    }
}

which is why you can represent larger numbers, but the accuracy diminishes

brittle thistle
#

so would what Praetor was talking about solve my issue in this case? making percent, max, and k all doubles instead of floats?

pallid venture
#

in your case 'k' represents an index, so that should stay as an integer

brittle thistle
#

but won't dividing an integer by a double result in the same issue as dividing an int by an int?

#

or is that not a problem

wicked tapir
#

I can't think of any good reason to iterate over every single unit coordinate