Thread: How to set a number of decimal spaces?

  1. #1
    Registered User
    Join Date
    Aug 2007
    Posts
    33

    How to set a number of decimal spaces?

    I was wandering if anyone coulda tell me how to set a 'double' to only output to 2 decimal spots only.

    For example...

    double ans;
    double a = 2;
    double b = 3;
    ans = 2/3;

    Normally, as an output, it would give me, 0.66666667... How would i make it so it only gives me 0.67 ?

  2. #2
    Sweet
    Join Date
    Aug 2002
    Location
    Tucson, Arizona
    Posts
    1,820
    Is this a console app or a windows application?

    Actually just look at this: http://msdn2.microsoft.com/en-us/lib...be(VS.80).aspx

  3. #3
    Registered User
    Join Date
    Aug 2007
    Posts
    33
    hmm, it was application. But ive solved the problem...

    Code:
    y = 6.7653
    answery.Text = Convert.ToString(y= Math.Round(y,2))

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. memory issue
    By t014y in forum C Programming
    Replies: 2
    Last Post: 02-21-2009, 12:37 AM
  2. Learning Memory, Ins and Outs?
    By Zoiked in forum C Programming
    Replies: 1
    Last Post: 08-27-2007, 04:43 PM
  3. Help counting number of bits set in an integer
    By JayDiddums10 in forum C Programming
    Replies: 5
    Last Post: 12-07-2006, 03:21 PM
  4. converting a hex number to decimal???
    By Unregistered in forum Game Programming
    Replies: 8
    Last Post: 04-13-2002, 05:46 PM
  5. Help! Can't read decimal number
    By Unregistered in forum C Programming
    Replies: 2
    Last Post: 09-07-2001, 02:09 AM