|
|
(10 intermediate revisions by 3 users not shown) |
Line 1: |
Line 1: |
| FormatCurrency(''expression''[, ''fractionaldigits''[, ''leadingdigit''[, ''parensfornegative''[, ''groupdigits'']]]])
| | Format(''string'', ''replace0''[,''replace1''...]) |
| | | Format(''string'', {replace object}) |
| FormatDateTime(''date''[, ''formatname''])
| |
| | |
| FormatNumber(''expression''[, ''fractionaldigits''[, ''leadingdigit''[, ''parensfornegative''[, ''groupdigits'']]]])
| |
| | |
| FormatPercent(''expression''[, ''fractionaldigits''[,''leadingdigit''[, ''parensfornegative''[, ''groupdigits'']]]])
| |
| | |
|
| |
|
| == Description == | | == Description == |
|
| |
|
| FormatCurrency, FormatNumber, and FormatPercent return a string obtained by formatting the given expression as a currency, number, or percent. The required parameter, ''expression'', is any valid expression of the given type.
| | Replaces {n} placeholders with arguments. One or more arguments can be passed, in addition to the string itself, to insert into the string. Arguments can be three different style: |
| | | <ol> |
| The optional parameter, ''fractionaldigits'', is a numeric expression representing the number of digits to print after the decimal. The default is -1 which uses the system settings.
| | <li>{} Empty brackets. Placeholders are replaced with arguments in the same order as they appear in the function call. |
| | | <li>{1] Brackets with a number. Placeholders are replaced by the argument number as it appears in the function call. |
| The optional parameters, ''leadingdigit'', ''parensfornegative'', and ''groupdigits'', are tristate values. See table below.
| | <li>{name} Brackets with a name. Placeholders are replaced by the value of the name in the argument object. |
| | </ol> |
|
| |
|
| ''leadingdigit'' specifies whether a leading zero is printed for numbers with only fractional parts.
| | == Example == |
|
| |
|
| ''parensfornegative'' specifies if negative values are to be printed with enclosing parentheses.
| | <tabber> |
| | JavaScript= |
| | <syntaxhighlight lang="JavaScript"> |
| | guy = {first: "Eric", last: "Cartman"}; |
|
| |
|
| ''groupdigits'' specifies if numbers are to be printed in groups using the systems group delimiter.
| | NSB.Print("hello {} and {}".format("you", "bob")); |
| | NSB.Print("hello {0} and {1}".format("you", "bob")); |
| | NSB.Print("hello {first} {last}".format(guy)); |
| | NSB.Print("hello {0} and {1} and {a}".format("you", "bob", {a:"mary"})); |
| | NSB.Print("hello {0} and {1} and {a} and {2}".format("you", "bob", "jill", {a:"mary"})); |
| | </syntaxhighlight> |
| | |-| |
| | BASIC= |
| | <syntaxhighlight lang="vb.net"> |
| | guy = {first: "Eric", last: "Cartman"} |
|
| |
|
| '''Tristate values'''
| | Print Format("hello {} and {}", "you", "bob") |
| | | Print Format("hello {0} And {1}", "you", "bob") |
| {| class="wikitable" | | Print Format("hello {first} {last}",guy) |
| |-
| | Print Format("hello {0} and {1} and {a}", "you", "bob", {a:"mary"}) |
| ! Name !! Value !! Description
| | Print Format("hello {0} and {1} and {a} and {2}", "you", "bob", "jill", {a:"mary"}) |
| |-
| | </syntaxhighlight> |
| | True || -1 || True
| | </tabber> |
| |-
| |
| | False || 0 || False
| |
| |-
| |
| | TriStateUseDefault || -2 || Use system settings
| |
| |}
| |
| | |
| FormatDateTime returns a string obtained by formatting a date. The required parameter, ''date'', is any valid expression that represents a date. The optional parameter, ''formatname'', is a numeric expression or constant that specifies how the date is formatted.
| |
| | |
| '''formatname constants'''
| |
| | |
| {| class="wikitable" | |
| |-
| |
| ! Constant !! Value !! Description !! Sample
| |
| |-
| |
| | vbGeneralDate || 0 || Short date, Long time || 6/04/2013 00:05:57 PM
| |
| |-
| |
| | vbLongDate || 1 || Long date || Tuesday, June 4, 2013
| |
| |-
| |
| | vbShortDate || 2 || Short date || 6/04/2013
| |
| |-
| |
| | vbLongTime || 3 || Long time || 00:05:57 PM
| |
| |-
| |
| | vbShortTime || 4 || Short time || 17:57
| |
| |-
| |
| | vbYYYYMMDD || 5 || || 20130604
| |
| |-
| |
| | vbDDdotMMdotYY || 6|| || 04.06.13
| |
| |-
| |
| | vbDDdotMMdotYYYY || 7 || || 04.06.2013
| |
| |-
| |
| | vbYYslashMMslashDD || 8 || || 13/06/04
| |
| |-
| |
| | vbDDslashMMslashYY || 9 || || 2013-06-04
| |
| |-
| |
| | vbYYYYhyphenMMhyphenDD || 10 || || 2013-10-30
| |
| |}
| |
| | |
| The following are also allowed as ''format name'':
| |
| "DD.MM.YY", "DD.MM.YYYY", "DD/MM/YY", "DD/MM/YYYY", "DD-MM-YY", "DD-MM-YYYY", "DDMMYY", "DDMMYYYY", "YY.MM.DD", "YYYY.MM.DD", "YY/MM/DD", "YYYY/MM/DD", "YY-MM-DD", "YYYY-MM-DD", "YYMMDD", "YYYYMMDD", "MM.DD.YY", "MM.DD.YYYY", "MM/DD/YY", "MM/DD/YYYY", "MM-DD-YY", "MM-DD-YYYY", "MMDDYY", "MMDDYYYY",
| |
| | |
| == Example (Basic) ==
| |
| | |
| <pre> | |
| Rem Format Functions
| |
| Dim UseDefault
| |
| UseDefault=-2
| |
| 'Currency
| |
| Print FormatCurrency(-3.5, -1, TristateUseDefault, True)
| |
| Print FormatCurrency(123456, 0,True, False, True)
| |
| 'Date/Time
| |
| Print FormatDateTime(Now)
| |
| Print FormatDateTime(Birthdate, vbLongDate)
| |
| 'General Numbers
| |
| Print FormatNumber(-0.1429, 6,False)
| |
| Print FormatNumber(987654.321, 3, True, False, True)
| |
| 'Percentages
| |
| Print FormatPercent(0.007, 2, False)
| |
| Print FormatPercent(1234.56, 0,True, False, False)
| |
| </pre>
| |
| | |
| == Example (JavaScript) ==
| |
| <pre>
| |
| NSB.Print(FormatCurrency(-3.5, 2, 0, true));
| |
| NSB.Print(FormatCurrency(123456, 2, true, false, true));
| |
| </pre> | |
|
| |
|
| == Output == | | == Output == |
| <pre> | | <pre> |
| ($3.50)
| | hello you and bob |
| $123,456
| | hello you and bob |
| 8/18/1998 10:44 PM
| | hello Eric Cartman |
| August 18, 1998
| | hello you and bob and mary |
| -.142900
| | hello you and bob and mary and jill |
| 987,654.321
| |
| .70%
| |
| 123456%
| |
| (sample output is system dependant)
| |
| </pre> | | </pre> |
|
| |
|
Line 111: |
Line 49: |
|
| |
|
| [[Category:Strings]] | | [[Category:Strings]] |
| | |
| | [[Category:BASIC Functions]] |
Format(string, replace0[,replace1...])
Format(string, {replace object})
Description
Replaces {n} placeholders with arguments. One or more arguments can be passed, in addition to the string itself, to insert into the string. Arguments can be three different style:
- {} Empty brackets. Placeholders are replaced with arguments in the same order as they appear in the function call.
- {1] Brackets with a number. Placeholders are replaced by the argument number as it appears in the function call.
- {name} Brackets with a name. Placeholders are replaced by the value of the name in the argument object.
Example
guy = {first: "Eric", last: "Cartman"};
NSB.Print("hello {} and {}".format("you", "bob"));
NSB.Print("hello {0} and {1}".format("you", "bob"));
NSB.Print("hello {first} {last}".format(guy));
NSB.Print("hello {0} and {1} and {a}".format("you", "bob", {a:"mary"}));
NSB.Print("hello {0} and {1} and {a} and {2}".format("you", "bob", "jill", {a:"mary"}));
guy = {first: "Eric", last: "Cartman"}
Print Format("hello {} and {}", "you", "bob")
Print Format("hello {0} And {1}", "you", "bob")
Print Format("hello {first} {last}",guy)
Print Format("hello {0} and {1} and {a}", "you", "bob", {a:"mary"})
Print Format("hello {0} and {1} and {a} and {2}", "you", "bob", "jill", {a:"mary"})
Output
hello you and bob
hello you and bob
hello Eric Cartman
hello you and bob and mary
hello you and bob and mary and jill