Formatting a number without rounding

Discussion in 'ASP .Net' started by Thor W Hammer, Nov 22, 2005.

  1. How can we format a decimal variable so that it has two decimal digits but
    not rounding it. Like this:
    Original value: 5.225;
    Output: 2.22; and NOT 2.23
     
    Thor W Hammer, Nov 22, 2005
    #1
    1. Advertisements

  2. Thor W Hammer

    Karl Seguin Guest

    *shrug* an annoyance to be sure :) There's no built-in method. Math.Floor
    works on integers. Math.Round does banker's rounding. All the formatters
    will automatically round.

    Personally, i'd just turn it into a string and chop it up!

    Karl
    --
    MY ASP.Net tutorials
    http://www.openmymind.net/


    "Thor W Hammer" <> wrote in message
    news:43834bd5$...
    > How can we format a decimal variable so that it has two decimal digits but
    > not rounding it. Like this:
    > Original value: 5.225;
    > Output: 2.22; and NOT 2.23
    >
     
    Karl Seguin, Nov 22, 2005
    #2
    1. Advertisements

  3. Thor W Hammer

    Karl Seguin Guest

    Uhmm..here's a better one, multiple by 100, floor it, and divide by 100 :)

    decimal d = 101.328m;
    Math.Floor(((double)d*100))/100;

    Karl

    --
    MY ASP.Net tutorials
    http://www.openmymind.net/


    "Thor W Hammer" <> wrote in message
    news:43834bd5$...
    > How can we format a decimal variable so that it has two decimal digits but
    > not rounding it. Like this:
    > Original value: 5.225;
    > Output: 2.22; and NOT 2.23
    >
     
    Karl Seguin, Nov 22, 2005
    #3
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. iksrazal
    Replies:
    1
    Views:
    766
    Chris Smith
    Jul 3, 2003
  2. Sooha Park Lee

    Rounding a floating point number declared in "double"

    Sooha Park Lee, Jul 16, 2003, in forum: C Programming
    Replies:
    2
    Views:
    512
    Mark McIntyre
    Jul 16, 2003
  3. Sooha Park Lee

    Rounding a floating point number declared in "double"

    Sooha Park Lee, Jul 16, 2003, in forum: C Programming
    Replies:
    2
    Views:
    342
    martinh
    Jul 17, 2003
  4. NoKetch

    Rounding to next highest number?

    NoKetch, Dec 15, 2003, in forum: C Programming
    Replies:
    7
    Views:
    615
    Mark McIntyre
    Dec 15, 2003
  5. jacob navia

    Rounding a floating point number

    jacob navia, Feb 25, 2008, in forum: C Programming
    Replies:
    21
    Views:
    882
    Bartc
    Feb 28, 2008
Loading...

Share This Page