1

I have this code:

var t = (timer2Seconds / 10).ToString()

When timer2Seconds is 100 then t is 100
When timer2Seconds is 99 then t is 9

Is there a way that I can make it round up so that:

When timer2Seconds is 99 then t is 10
When timer2Seconds is 91 then t is 10 
When timer2Seconds is 90 then t is 9
Alan2
  • 21,590
  • 73
  • 223
  • 402

1 Answers1

1

Use formula:

var d = 10;
var t = (timer2Seconds + d - 1) / d;

It works with integers and rounds up.

Backs
  • 23,679
  • 4
  • 50
  • 77