CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Mar 2012
    Posts
    2

    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

  2. #2
    Join Date
    Feb 2012
    Location
    Strasbourg, France
    Posts
    116

    Re: Type double multiplication

    Console.WriteLine(x.ToString() + "*100=" + (x * 100));

    //18.9*100=1890

    just removed the cast to Int32

  3. #3
    Join Date
    Mar 2012
    Posts
    2

    Re: Type double multiplication

    And this code work right:
    Convert.ToInt32(x*100)
    and when x=9.9 all work right too...why so?

  4. #4
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    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
  •  





Click Here to Expand Forum to Full Width

Featured