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

Recommended Answers

All 5 Replies

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

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

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);
commented: 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);

Thanks, it worked :)

You're welcome my friend.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.