round up

Discussion in 'ASP General' started by joeandtel, Feb 18, 2004.

  1. joeandtel

    joeandtel Guest

    If I have a value that is 53.123499999, how can I round it to 53.12?
    joeandtel, Feb 18, 2004
    #1
    1. Advertising

  2. joeandtel wrote:
    > If I have a value that is 53.123499999, how can I round it to 53.12?


    Umm - that's not rounding "up".

    In vbscript, you can use the round() function.

    Here's a link to the downloadable documentation:
    http://www.microsoft.com/downloads/...48-207d-4be1-8a76-1c4099d7bbb9&DisplayLang=en

    Bob Barrows
    --
    Microsoft MVP -- ASP/ASP.NET
    Please reply to the newsgroup. The email account listed in my From
    header is my spam trap, so I don't check it very often. You will get a
    quicker response by posting to the newsgroup.
    Bob Barrows [MVP], Feb 18, 2004
    #2
    1. Advertising

  3. Peter Foti wrote:
    > "Bob Barrows [MVP]" <> wrote in message
    > news:...
    >> joeandtel wrote:
    >>> If I have a value that is 53.123499999, how can I round it to 53.12?

    >>
    >> Umm - that's not rounding "up".

    >
    >
    > Bob, he didn't ask to round up... just to round it.
    >

    Look at the subject
    --
    Microsoft MVP -- ASP/ASP.NET
    Please reply to the newsgroup. The email account listed in my From
    header is my spam trap, so I don't check it very often. You will get a
    quicker response by posting to the newsgroup.
    Bob Barrows [MVP], Feb 18, 2004
    #3
  4. Peter Foti wrote:
    >
    > You could, but it wouldn't provide the functionality that he's asking
    > for. The round function is foolishly implemented in my opinion. It
    > rounds even numbers down, and odd numbers up. Where would it ever be
    > useful to round
    > 22.5 to 22, and 21.5 to 22?
    >

    In financial situations. That's why it's called banker's rounding. It's
    intended to avoid the over-enrichment of one party vs. another in financial
    transactions involving rounding by randomizing which way the number in the
    middle will be rounded. Sometimes the bank will get the extra penny,
    sometimes the customer will get it. It would be unfair if one party or the
    other always got the extra penny, wouldn't it?

    Why is your definition the "correct" one? Rounding is defined as setting the
    value of a number to the closest rounded result. By this definition, the
    number ending in 5 cannot be rounded, since neither rounded result is closer
    to 5 than the other. So why do you insist it's correct to always round down
    (or up)? Why not use a method that results in half the numbers being
    rounded down, and half being rounded up? The aggregate result will probably
    be closer to the non-rounded aggregate result than if you chose to always
    round the middle number up or down.

    Bob Barrows
    --
    Microsoft MVP -- ASP/ASP.NET
    Please reply to the newsgroup. The email account listed in my From
    header is my spam trap, so I don't check it very often. You will get a
    quicker response by posting to the newsgroup.
    Bob Barrows [MVP], Feb 19, 2004
    #4
  5. joeandtel

    Evertjan. Guest

    =?Utf-8?B?am9lYW5kdGVs?= wrote on 18 feb 2004 in
    microsoft.public.inetserver.asp.general:

    > If I have a value that is 53.123499999, how can I round it to 53.12?


    The old and safe way:

    n = 53.123499999

    n = int( n * 100 + 0.5 ) / 100

    n = int(n) / 100

    Response.Write FormatNumber(n,2)

    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)
    Evertjan., Feb 19, 2004
    #5
  6. joeandtel

    Mark Schupp Guest

    > In school, I was taught that you rounded 1 - 4 down, and 5 - 9 up (the way
    > the FormatNumber does rounding). I don't ever remember being taught
    > banker's rounding. You learn something new every day. :)


    I used to get horribly upset when my children would come home and tell me
    that they were being taught to round that way (arithmetic rounding). I was
    taught the other way (banker's rounding). It wasn't until I researched the
    issue (to prove I was right, of course) that I found out that there were 2
    different ways. I guess it is logical to teach arithmetic rounding in a math
    class but there should at least be a mention of the other method.

    The trick is to be consistent. Another programmer and I once spent 3 days
    tracking down a 6 cent out of balance condition in a hospitals books (tried
    to give the accounting trolls the 6 cents but they wouldn't take it). The
    cause: in one place arithmetic rounding was used while banker's rounding was
    used elsewhere.

    --
    Mark Schupp
    Head of Development
    Integrity eLearning
    www.ielearning.com


    "Peter Foti" <> wrote in message
    news:...
    > "Bob Barrows [MVP]" <> wrote in message
    > news:...
    > > Peter Foti wrote:
    > > >
    > > > You could, but it wouldn't provide the functionality that he's asking
    > > > for. The round function is foolishly implemented in my opinion. It
    > > > rounds even numbers down, and odd numbers up. Where would it ever be
    > > > useful to round
    > > > 22.5 to 22, and 21.5 to 22?
    > > >

    > > In financial situations. That's why it's called banker's rounding. It's
    > > intended to avoid the over-enrichment of one party vs. another in

    > financial
    > > transactions involving rounding by randomizing which way the number in

    the
    > > middle will be rounded. Sometimes the bank will get the extra penny,
    > > sometimes the customer will get it. It would be unfair if one party or

    the
    > > other always got the extra penny, wouldn't it?

    >
    >
    > I've never heard of this before. Though it seems to make sense.
    >
    >
    > > Why is your definition the "correct" one? Rounding is defined as setting

    > the
    > > value of a number to the closest rounded result. By this definition, the
    > > number ending in 5 cannot be rounded, since neither rounded result is

    > closer
    > > to 5 than the other. So why do you insist it's correct to always round

    > down
    > > (or up)? Why not use a method that results in half the numbers being
    > > rounded down, and half being rounded up? The aggregate result will

    > probably
    > > be closer to the non-rounded aggregate result than if you chose to

    always
    > > round the middle number up or down.

    >
    >
    > In school, I was taught that you rounded 1 - 4 down, and 5 - 9 up (the way
    > the FormatNumber does rounding). I don't ever remember being taught
    > banker's rounding. You learn something new every day. :)
    >
    > -Pete
    >
    >
    Mark Schupp, Feb 19, 2004
    #6
    1. Advertising

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. Ruslan

    Round up

    Ruslan, Aug 3, 2003, in forum: ASP .Net
    Replies:
    2
    Views:
    1,702
    Ruslan
    Aug 4, 2003
  2. Peter Row
    Replies:
    1
    Views:
    690
    vMike
    Nov 26, 2003
  3. Replies:
    0
    Views:
    1,088
  4. OliverMarchand

    Float.round - should it be round-to-even

    OliverMarchand, Apr 12, 2006, in forum: Ruby
    Replies:
    2
    Views:
    220
    OliverMarchand
    Apr 12, 2006
  5. cerr

    reading file round and round

    cerr, Mar 19, 2010, in forum: Perl Misc
    Replies:
    6
    Views:
    178
    Peter J. Holzer
    Mar 20, 2010
Loading...

Share This Page