ASP Round() function BUSTED?!?

Results 1 to 4 of 4

Thread: ASP Round() function BUSTED?!?

  1. #1
    Scott Coleman Guest

    Default ASP Round() function BUSTED?!?

    I can&#039t get reliable results from the ASP Round() function. Here&#039s what I see:<BR><BR>Round(2.705,2) evaluates to 2.7 (wrong!)<BR>Round(2.715,2) evaluates to 2.72 (right)<BR>Round(2.725,2) evaluates to 2.72 (wrong!)<BR>Round(2.735,2) evaluates to 2.74 (right)<BR>Round(2.745,2) evaluates to 2.74 (wrong!)<BR>Round(2.755,2) evaluates to 2.76 (right)<BR>Round(2.765,2) evaluates to 2.76 (wrong!)<BR>Round(2.775,2) evaluates to 2.78 (right)<BR>Round(2.785,2) evaluates to 2.78 (wrong!)<BR>Round(2.795,2) evaluates to 2.8 (right)<BR><BR>Am I going crazy or is this really happening? If someone has had the same experience please confirm.. or if you know what&#039s going on please enlighten me. Thanks!

  2. #2
    Richard A. Lowe Guest

    Default RE: ASP Round() function BUSTED?!?

    Actually, that is the built functionality of the Round() function - it is called "Banker&#039s Rounding" and it has been used before, although I&#039m not sure why MS chose to put it in VBScript. As you can see when the number to the place left of the last digit is even, it rounds down.<BR><BR>You will have to write your own custom function to accomplish the more common sort of rounding you&#039re looking for (Hint: add 5 / (10 * # of decimal places) and truncate)<BR><BR>HTH,<BR>Richard

  3. #3
    Join Date
    Dec 1969

    Default Or Try FormatNumber()

    Or you can try the FormatNumber(variablename, numberofdigits). I believe this actually does the rounding you are looking for.<BR><BR>Let us know if it works better.<BR><BR>HTH<BR><BR>Jerry

  4. #4
    Scott Coleman Guest

    Default Thanks!

    Thanks folks, FormatNumber() does the trick. It peforms the conventional "rounding" that we all learn in grade school. Why MS would use Banker&#039s Rounding is beyond me...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts