Round Function [VBA]

Rounds a numeric value to a specified number of decimal digits.

warning

Konstante, funtzio edo objektu hau Option VBASupport 1 instrukzioa programa-kode exekutagarriko modulu batean kokatuta gaitzen da.


This function implements the rounding rule known as "round-to-even". With this rule, whenever the difference between the number to be rounded and its nearest integer is equal to 0.5, the number is rounded to the nearest even number. See the examples below to learn more about this rule.

note

Kontuan izan VBA lengoaiako Round funtzioak eta LibreOffice Calc-eko Round funtzioak desberdin funtzioantzen dutela. Calc aplikazioan, biribilduko den zenbakiaren eta osoko balio hurbilenaren diferentzia 0.5 bada, zenbakia gorantz biribilduko da. Hortaz, Calc-en 2.5 zenbakia 3 baliora biribilduko da eta VBA lengoaian, Round funtzioarekin, 2.5 zenbakia 2 baliora biribilduko da "biribildu bikoitira" erregelaren ondorioz.


Sintaxia:

Round(expression [,numdecimalplaces])

Itzulera-balioa:

Double

Parametroak:

expression: The numeric expression to be rounded.

numdecimalplaces: Optional argument that specifies the number of decimal digits in the resulting rounded value. The default value is 0.

Errore-kodeak:

5 Prozedura-deia ez baliozkoa

Adibidea:


    Option VBASupport 1
    Sub Example_Round
        Dim r 
        r = Pi
        print r ' 3,14159265358979
        print Round(r, 5) ' 3,14159
        r = exp(1)
        print r ' 2,71828182845904
        print Round(r) ' 3
    End Sub
  

The following examples illustrate the "round-to-even" rule:


    ' Rounding to the nearest integer (decimalplaces = 0)
    MsgBox Round(3.5) ' 4
    MsgBox Round(4.5) ' 4
    MsgBox Round(5.5) ' 6
    MsgBox Round(6.5) ' 6
    ' Rounding with 2 decimal digits (decimalplaces = 2)
    MsgBox Round(1.555, 2) ' 1.56
    MsgBox Round(1.565, 2) ' 1.56
    MsgBox Round(1.575, 2) ' 1.58
    MsgBox Round(1.585, 2) ' 1.58