Round in Oracle/vba

Source: Internet
Author: User

VBA Round is based on the silver Connoisseur algorithm (rounds to the nearest even number)

Round (1.5) = 2

Round (0.5) = 0

Implementing Banker Algorithms in Oracle

sql> Create or Replace function Bankers_round (val number, rnd_digit number: = 0) return number is

2 V_rnd_digit number;

3 V_remainder number;

4 begin

5 V_rnd_digit: = Trunc (Rnd_digit);

6

7 V_remainder: = (Val-trunc (val,v_rnd_digit)) * Power (10,v_rnd_digit + 1);

8

9 If Abs (V_remainder) < 5

Ten or (Abs (v_remainder) = 5 and mod (Trunc (val * Power (10,v_rnd_digit)), 2) = 0) Then

return trunc (Val,v_rnd_digit);

Else

Return round (val,v_rnd_digit);

+ End If;

The end;

16/

?

Sql> Select Bankers_round ( -123.45, 1) from dual;

?

Bankers_round ( -123.45,1)

------------------------

-123.4

?

Sql> Select Bankers_round ( -123.55, 1) from dual;

?

Bankers_round ( -123.55,1)

------------------------

-123.6

?

Sql> Select Bankers_round ( -123.65, 1) from dual;

?

Bankers_round ( -123.65,1)

------------------------

-123.6

?

Sql> Select Bankers_round ( -123.75, 1) from dual;

?

Bankers_round ( -123.75,1)

------------------------

-123.8

To implement normal rounding in VBA

Round (12.45+0.000000001,1)

Http://blogs.msdn.com/b/ericlippert/archive/2003/09/26/bankers-rounding.aspx

Round in Oracle/vba

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.