web analytics
How to Format Numbers in VBScript? Options
codeling
Posted: Sunday, January 10, 2016 12:22:17 PM

Rank:Advanced Member
Groups: Member
Joined: 12/11/2015
Posts: 738
Points: 3102

The following table shows the possible number formatting functions in VBScript. Number Formatting Functions help the developers to handle numbers in an efficient way and express the numbers in the desired format.

Function Description
FormatNumber A Function, which would return an expression formatted as a number
FormatPercent A Function, which would return an expression formatted as a percentage

 

FormatNumber() Function

The FormatNumber function in VBScript returns an expression formatted as a number.

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

 

Parameter Description
Expression Required. The expression to be formatted
NumDigAfterDec Optional. Indicates how many places to the right of the decimal are displayed. Default is -1 (the computer's regional settings are used)
IncLeadingDig Optional. Indicates whether or not a leading zero is displayed for fractional values:
  • -2 = TristateUseDefault - Use the computer's regional settings
  • -1 = TristateTrue - True
  • 0 = TristateFalse - False
UseParForNegNum Optional. Indicates whether or not to place negative values within parentheses:
  • -2 = TristateUseDefault - Use the computer's regional settings
  • -1 = TristateTrue - True
  • 0 = TristateFalse - False
GroupDig Optional. Indicates whether or not numbers are grouped using the group delimiter specified in the computer's regional settings:
  • -2 = TristateUseDefault - Use the computer's regional settings
  • -1 = TristateTrue - True
  • 0 = TristateFalse - False
 

Examples

FormatNumber(10000)       '10,000.00

FormatNumber(10000, 0)    '10,000
FormatNumber(10000, 2)    '10,000.00

FormatNumber(.15,,0)      '.15
FormatNumber(.15,,-1)     '0.15

FormatNumber(-10,,,0)     '-10
FormatNumber(-50,,,-1)    '(10)

FormatNumber(10000,,,,0)  '10000.00
FormatNumber(10000,,,,-1) '10,000.00

 

Sponsor
Posted: Sunday, January 10, 2016 12:22:17 PM
 
Users browsing this topic
Guest

Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.


© 2017 Digcode.com. All rights reserved.