FormatNumber Function

Tips >>ASP Functions

WANTS TO MAKE SOFTWARE WITHOUT KNOWLEDGE OF ASP? CLICK HERE

The FormatNumber function return a formatted number value for the numeric expression. The FormatNumber function takes the contents of a number type variable and returns the contents in the specified format. Frequently you want a number to appear in a certain format. The most commands requests are for a set total number of digits and a set number of digits to the right of the decimal place. Less frequently there is a call for negative amounts displayed in parenthesis or that there should be leading zeros.

The Syntax of FormatNumber function is :-

FormatNumber(Expression[,NumDigAfterDec[
,IncLeadingDig[,UseParForNegNum[,GroupDig]]]])

Example#1 :-

Code :-
document.write(FormatNumber(20000))
Output :-
20,000.00

Example#2 :-

Code :-
document.write(FormatNumber(20000.578,2))
Output :-

20,000.58

Example#3 :-

Code :-
document.write(FormatNumber(20000.578,2,,,0))
Output :-
20000.58

Example#4 :-

Code :-
<% =FormatNumber(12345) %>
Output :-
12,345.00

Note :- These function rounds off the values. If number written after decimal is less than 5 nothing is written after decimal. If number written after the decimal is more than 5 the round off value is written.

Example#5 :-

Code :-
<% =FormatNumber(12345.67899) %>
Output :-
12,345.68

There are Four Optional Arguments :-

  1. Num Digits After Decimal :- The optional Num Digits After Decimal argument allows you to choose the number of digits after the decimal.

    Example#1 :-

    Code :-
    <% =FormatNumber(12345.67899, 4) %>
    Output :-
    12,345.6790

  2. Include Leading Digit :- The optional Include Leading Digit argument includes the leading zero.

    You must only use the constant or value from the Tristate CONSTANTS for this argument.

    CONSTANT VALUE DESCRIPTION
    TristateTrue -1 True, will use options
    TristateFalse 0 False,
    will not use options
    TristateUseDefault -2 Use default setting

    Example#1 :-

    Code :-
    <% =FormatNumber(.77, 4, -1) %>
    Output :-
    0.7700

  3. Use Parens For Negative Numbers :- The optional Use Parens For Negative Number argument replaces a negative sign with parentheses around the number.

    You must only use the constant or value from the Tristate CONSTANTS for this argument.

    CONSTANT VALUE DESCRIPTION
    TristateTrue -1 True, will use options
    TristateFalse 0 False, will not use
    options
    TristateUseDefault -2 Use default setting

    Example#1 :-

    Code :-
    <% =FormatNumber(-12345.67899, 2, 0, -1) %>
    Output :-
    12,345.68


  4. Group Digit :- The optional Group Digit argument allows the use of the options specified in the Regional Settings Properties in the Control Panel to display a number.

    You must only use the constant or value from the Tristate CONSTANTS for this argument.

    CONSTANT VALUE DESCRIPTION
    TristateTrue -1 True, will use options
    TristateFalse 0 False, will not use options
    TristateUseDefault -2 Use default setting


    Example#1 :-

    Code :-
    <% =FormatNumber(12345.67899, 2, 0, -1, -1) %>
    Output :-
    12,345.68

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

Whatsapp Icon +91-9967648641

Whatsapp Icon +91-9967648641