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
  • 23,493
  • 79
  • 256
  • 450

1 Answers1

1

Use formula:

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

It works with integers and rounds up.

Backs
  • 24,430
  • 5
  • 58
  • 85