Timing issue on android device. (Timer/Time.deltaTime; comparing float values)

Hello,
i have a game where I time/measure the reaction time of a player. After that i start a timer/counter which increases by Time.deltaTime and I display it as a string.

To ensure that the timer doesnt “overshoot” on low fps i wrote this code:

...
float timeCounter, reactionTime;
...

//This method gets called from Update()
void TimerMethodABC()
{
  //Increase Timer for player
        if (timeCounter < reactionTime && increaseTimer) {
            timeCounter += Time.deltaTime;
            timeCounter = (timeCounter > reactionTime) ? reactionTime : timeCounter; //Limit
            player.DisplayTimer(timeCounter); // display in ui  >> reactionTime.text = timeCounter.ToString("F2");

            if(timeCounter >= reactionTime)
                increaseTimer = false;
        }
}
...

When i play my game in editor it works as expected, even if lock the fps down to 10.
As soon as i play it on my android phone it doesnt work as expected. The displayed time does overshoot the reactionTime.

Example:
reactionTime from the player => reactionTime = 1.9;
displayed time in the editor => 1.9
displayed time in the android build => 1.92 (for example)

I dont understand how this is actual possible when I set the TimeCounter equal to the reactionTime (if its higher) just one line before displaying it. Is there a better way to compare floats maybe?

I would appreciate any help.

Is it possible that the reactionTime is actually 1.92, but you are displaying it in a way that limits the precision to only one decimal place, so that it looks like 1.9?

1 Like

I am using this line of code to display it (same way in editor and game so): sometextcomponent.text = timeCounter.ToString("F2");

In your OP, reactionTime is a float, but in the post above you appear to be using it as a UI.Text, and you are using it to display the value of the timeCounter variable. I was asking about the reactionTime variable in the OP.

Thanks for your reply.
Sorry i messed this post up , i edit it. I also use the same function “ToString(“F2”);” to display the reaction time first.

I was searching at the wrong point, your hint pushed me back onto the right way, thanks!
It had something to do with when/how i display the reactionTime. I switched to LateUpdate() in my UI-Component and now it works. The reason why it worked in the editor is probably that the script execution order is different between the editor and the build.