Weird value display

Im making an idle clicker game and i want to show the current score and that works good but i have a production per second in this case its currently 0.2 and when i add that to the scoor it seems to work great in the beginning but once it gets to 3 its returns 3.000000001 when it gets to 4 everything is normal again but once it gets to 5 it turns into 5.199999999. Can anybody tell me why and what i need to change? and how do i get it to not show Decimals at all ive tried the rounding functions but that didnt seem to work

// Used for displaying the score

    float score = Click.score; 
    Mathf.Floor(score);
    string counting = ("Collected:" + score);
    score_UIText.text = counting;
// Adding the Productions per second(0.2 in this case) to the score

score = score + pps;
        Debug.Log(score);
        Debug.Log(pps)
;

pps and score are both floats

Has been asked and is answered many times before*. There is nothing weird about it and completely according to the specification. You can see more about it here:
https://www.h-schmidt.net/FloatConverter/IEEE754.html

For displaying it without all decimals, simply format it:

Debug.Log(score.ToString('0.00"));

*: The problem is that you can’t really find these topics, because of titles like “Weird value display”.

1 Like

Thanks man didnt know that it wouldnt actually be stored as 0.2 and also thanks for the display without decimals really helped me out ^^. have a good day and again thank you