-
March 2nd, 2012, 09:02 AM
#1
Type double multiplication
Hello. What code would give the multiplication of 1890? Thx
double x = 18.9;
Console.WriteLine(x.ToString()+"*100="+(Int32)(x*100));//18.9*100=1889
-
March 2nd, 2012, 10:07 AM
#2
Re: Type double multiplication
Console.WriteLine(x.ToString() + "*100=" + (x * 100));
//18.9*100=1890
just removed the cast to Int32
-
March 2nd, 2012, 01:56 PM
#3
Re: Type double multiplication
And this code work right:
Convert.ToInt32(x*100)
and when x=9.9 all work right too...why so?
-
March 2nd, 2012, 09:15 PM
#4
Re: Type double multiplication
9.9*100 = 990 why would you think that would not work ?
if you tried the convert on just the 9.9 then you would get a different result as it is not a whole number
Always use [code][/code] tags when posting code.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|