- Home /
How to convert timer to minutes, seconds and cents
Hi All! I have a timer that calculate the time of a lap in a race game. I have the minutes and the seconds:
 int curMin = Mathf.FloorToInt (lapTime / 60F);
         int curSec = Mathf.FloorToInt (lapTime - curMin * 60);
         int curCent = Mathf.FloorToInt (lapTime - curSec * 100);
 
         string curLapTime = string.Format ("{0:0}:{1:00}:{2:00}", curMin, curSec, curCent);
but the cents of seconds don't work... What is the right calc of the cents of seconds?
Answer by zharik86 · Aug 22, 2014 at 07:01 PM
Correct calculate your "cents":
  int curCent = Mathf.FloorToInt (lapTime - curMin *60 - curSec * 100);
I hope that it will help you.
I've found another way of counting cents of seconds:
 int curCents = $$anonymous$$athf.FloorToInt ((lapTime * 100) % 100);
Thanks anyway! Hope this helps newbees of c# like me! (I've searched a lot after posting at unity community)
Guys it's very simple. Try this one ## CountDown In hours, $$anonymous$$inutes and seconds ##
 countDown -= Time.deltaTime;
 countDownText.text = ((($$anonymous$$athf.Floor(countDown / 3600f)) % 60).ToString("00")) + ":" + ((($$anonymous$$athf.Floor(countDown / 60f)) % 60).ToString("00")) + ":" + ($$anonymous$$athf.Floor(countDown % 60f).ToString("00")); 
Answer by KMKxJOEY1 · Aug 22, 2014 at 07:05 PM
 int curCent = Mathf.FloorToInt (lapTime - (curMin*60) - (curSec * 100));
Answer by komal2992 · Jan 17, 2018 at 07:02 AM
Guys it's very simple. Try this one ## CountDown In hours, Minutes and seconds ##
 countDown -= Time.deltaTime;
 countDownText.text = (((Mathf.Floor(countDown / 3600f)) % 60).ToString("00")) + ":" + (((Mathf.Floor(countDown / 60f)) % 60).ToString("00")) + ":" + (Mathf.Floor(countDown % 60f).ToString("00"));
Your answer
 
 
             Follow this Question
Related Questions
String format to show float as time 3 Answers
how to Format time float (days/hours/minutes/seconds) 1 Answer
Multiple Cars not working 1 Answer
System.DateTime truncate Milliseconds 1 Answer
Distribute terrain in zones 3 Answers
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                