Round Function
 
Tips >>ASP Functions

WANTS TO MAKE SOFTWARE WITHOUT KNOWLEDGE OF ASP? CLICK HERE

The Round function rounds a number. The round function in ASP lets you round a number off to a set number of decimal points. This is great, for example, to round dollar amounts off to the nearest cents. The Round function rounds off a floating-point number (decimal) to a specified number of decimal places. All you do is use the Round command, and provide the number of decimal points to round it to. For example, if you have a number and want it to have only 2 decimals points so it looks like a dollar value, you would say :-

Response.write "Your final total is: $" & Round(CartAmt,2) & " Dollars."

If you want to estimate the number of visitors you get in a given day based on your monthly traffic, you don't want to end up with partial visitors! So in this case you'd round to zero decimal points -

response.write "I get about " & Round(MonthVisit,0) & " visitors each day."

The Syntax of the Round function is :-

Round(expression[,numdecimalplaces])

Example#1 :-

Code :-
dim x
x=24.13278
document.write(Round(x))
Output :-
24

Example#2 :-

Code :-
dim x
x=24.13278
document.write(Round(x,2))
Output :-
24.13

There is One Mandatory Argument :-

  • Number :- The Number argument is the number you wish to round off. If the number of decimal places to round off to is not specified, the number is rounded off to an integer.

    Example#1 :-

    Code :-
    <%
    =Round(1.123456789)
    %>
    Output :-
    1


    Example#2 :-

    Code :-
    <%
    =Round(9.87654321)
    %>
    Output :-
    10

    Note :- The negative numbers are rounded down (more negative).


    Example#3 :-

    Code :-
    <% =Round(-2.899999999) %>
    Output :-
    -3

    Note :- Even numbers that are composed of the exact decimal .5, such as 2.5, 4.50, or 22.500000, are rounded down (towards the negative direction). Negative, even numbers are rounded up (towards the postive direction). Odd number that are composed of the exact decimal .5, such as 1.5, 3.50, or 21.500000, are rounded up (towards the positive direction). Negative, odd numbers are rounded down (towards the negative direction).

    Example#4 :-

    Code :-
    <% =Round(4.50) %>
    <% =Round(3.5) %>
    <% =Round(2.5000) %>
    <% =Round(1.5) %>
    <% =Round(0.50000) %>
    <% =Round(-0.50) %>
    <% =Round(-1.5) %>
    <% =Round(-2.50000000) %>
    <% =Round(-3.5) %>
    <% =Round(-4.5) %>
    Output :-
    4
    4
    2
    2
    0
    0
    -2
    -2
    -4
    -4

There is One Optional Argument :-

  • NumDecimalPlaces :- The optional NumDecimalPlaces argument specifies how many decimal places to round off to. A number indicating how many places to the right of the decimal are included in the rounding. If omitted, integers are returned by the Round function. Optional.


    Example#1 :-

    Code :-
    <% =Round(1.123456789, 6) %>
    Output :-
    1.123457

    Note :- The negative numbers are rounded down (more negative).

    Example#2 :-

    Code :-
    <% =Round(-2.899999999, 2) %>
    Output :-

    -2.9


    Note :- Round to even is a statistically more accurate rounding algorithm than round to larger.

E-mail : sales@virtualsplat.com
Phone : +91-9892413501

Whatsapp Icon +91-9967648641

Whatsapp Icon +91-9967648641