0

I'm making a program that divides by 1000. It works fine until it divides by a number higher than itself. For example

double asdf = (1000 / 3000);
            Math.Round(asdf);
            txtSpeed.Text = asdf.ToString();

When it divides by a number higher than 1000 it just gives me 0. Anyone know what's causing this?

Thanks,

SiPex

3
Contributors
5
Replies
6
Views
9 Years
Discussion Span
Last Post by Ramy Mahrous
Featured Replies
  • Developers just don't look at methods documentation!! Round method [b]returns[/b] the rounded number that's your problem, friend! [code] double d = 1000.0 / 3000.0; d = Math.Round(d, 2); Console.WriteLine(d); [/code] Read More

0

How about the fact that you are rounding the number!

try specifing the number of rounding digits...

Math.Round(asdf, 2)

would give you 0.00 percision

0

How about the fact that you are rounding the number!

try specifing the number of rounding digits...

Math.Round(asdf, 2)

would give you 0.00 percision

OK, i tried

double asdf = (1000 / 3000);
            Math.Round(asdf, 2);           
            Console.WriteLine(asdf);
            Console.ReadLine();

Still got 0

Any other suggestions?

Thanks

1

Developers just don't look at methods documentation!!
Round method returns the rounded number that's your problem, friend!

double d = 1000.0 / 3000.0;
d = Math.Round(d, 2);
Console.WriteLine(d);
Votes + Comments
Thanks.
0

Developers just don't look at methods documentation!!
Round method returns the rounded number that's your problem, friend!

double d = 1000.0 / 3000.0;
d = Math.Round(d, 2);
Console.WriteLine(d);

Thanks, it worked :)

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.