FORMATNUMBER |
FORMATNUMBER(expression [,numdigitsafter] [,includeleadingdigit] [,negativeuseparens] [,groupdigits]) |
Returns the expression formatted as a number (String). |
expression | The 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 |
* 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 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 FORMATPERCENT function to return an expression formatted as a percentage. * The equivalent .NET function is Microsoft.VisualBasic.Strings.FormatNumber * For the Microsoft documentation refer to learn.microsoft.com |
Debug.Print FormatNumber(123) '= 123.00
Debug.Print FormatNumber(123, -1) '= 123.00
Debug.Print FormatNumber(123.456) '= 123.46
Debug.Print FormatNumber(123.456, -1) '= 123.46
Debug.Print FormatNumber(123.456, 3) '= 123.456
Debug.Print FormatNumber(123.456, 6) '= 123.456000
Debug.Print FormatNumber(0.456, , vbFalse) '= .46
Debug.Print FormatNumber(-40.456, , , vbTrue) '= (40.46)
Debug.Print FormatNumber(1000000, , , , vbFalse) '= 1000000.00
© 2024 Better Solutions Limited. All Rights Reserved. © 2024 Better Solutions Limited Top