FORMATPERCENT

FORMATPERCENT(expression [,numdigitsafter] [,includeleadingdigit] [,negativeuseparens] [,groupdigits])

Returns the expression formatted as a percentage (String).


expressionThe expression to be formatted.
numdigitsafter(Optional) The number -1 to 255 that specifies the number of places to the right of the decimal place (Regional)
includeleadingdigit(Optional) A vbTriState constant specifying if to include leading zeros (Integer):
-1 = vbTrue
0 = vbFalse
1 = vbUseDefault (Default)
useparensfornegativenumbers(Optional) A vbTriState constant specifying how to display negative numbers (Integer):
-1 = vbTrue
0 = vbFalse
1 = vbUseDefault (Default)
groupdigits(Optional) A vbTriState constant specifying if numbers are grouped (Integer):
-1 = vbTrue
0 = vbFalse
1 = vbUseDefault (Default)

REMARKS
* The "expression" is formatted as a percentage (multiplied by 100) with a trailing % characters.
* If "numdigitsafter" is left blank, then -1 is used.
* If "numdigitsafter" = -1, then Regional Settings are used. Control Panel, Region, Additional Settings, Number Tab, No. of digits after decimal.
* If "numdigitsafter" > 255, then a run-time error occurs.
* The default number of decimal places is usually 2.
* If "includeleadingdigit" is left blank, then vbUseDefault is used.
* If "includeleadingdigit" = vbUseDefault, then Regional Settings are used. Additional Settings, Numbers Tab, Display leading zeros.
* If "useparensfornegativenumbers" is left blank, then vbUseDefault is used.
* If "useparensfornegativenumbers" = vbUseDefault, then Regional Settings are used. Additional Settings, Numbers Tab, Negative number format.
* If "groupdigits" is left blank, then vbUseDefault is used.
* If "groupdigits" = vbUseDefault, then Regional Settings are used. Additional Settings, Numbers Tab, Digit grouping.
* You can use the FORMAT function to return a text string of a number or date in a particular format.
* You can use the FORMATCURRENCY function to return an expression formatted as a currency value.
* You can use the FORMATDATETIME function to return an expression formatted as a date or time.
* You can use the FORMATNUMBER function to return an expression formatted as a number.
* The equivalent .NET function is [[Microsoft.VisualBasic.Strings.FormatPercent]]
* For the Microsoft documentation refer to learn.microsoft.com

Debug.Print FormatPercent(123.456)                 '= 12,345.60%  
Debug.Print FormatPercent(123.456, 3) '= 12,345.600%
Debug.Print FormatPercent(0.456, , vbFalse) '= 45.60%
Debug.Print FormatPercent(-40.456, , , vbTrue) '= (4,045.60%)
Debug.Print FormatPercent(1000000, , , , vbFalse) '= 100000000.00%

© 2024 Better Solutions Limited. All Rights Reserved. © 2024 Better Solutions Limited Top