classical312
classical312

Reputation: 185

Show double format C#

I have random number:

Random log = new Random();

I use it on Timer:

timer1.Interval = log.Next(200000, 570000);

This part converting mili seconds in a minutes:

double timme = timer1.Interval / 1000 / 60;

So timme is always whole number, I want double. How I can do that?

Upvotes: 0

Views: 54

Answers (2)

Thiago Ferreira
Thiago Ferreira

Reputation: 651

Alternativelly, you can use suffixes:

double timme = timer1.Interval / 1000D / 60D;

The character "D" after a number indicates that the fixed number will be a double.

You can do this for decimals too, if needed:

decimal timme = timer1.Interval / 1000M / 60M;

More informating: here

Upvotes: 0

Mitch Wheat
Mitch Wheat

Reputation: 300579

You are experiencing integer division.

double timme = timer1.Interval / 1000.0 / 60.0;

(Strictly speaking only one of the two constants need to be floating point value)

Upvotes: 3

Related Questions