Format: Difference between revisions

From NSB App Studio
Jump to navigation Jump to search
Brendon (talk | contribs)
Created page with "<pre> FORMATCURRENCY(expression[, fractionaldigits[, leadingdigit[, parensfornegative[, groupdigits]]]]) FORMATDATETIME(date[, formatname]) FORMATNUMBER(exp..."
 
No edit summary
 
(31 intermediate revisions by 4 users not shown)
Line 1: Line 1:
<pre>
Format(''string'', ''replace0''[,''replace1''...])
FORMATCURRENCY(expression[, fractionaldigits[,
Format(''string'', {replace object})
 
== Description ==


                leadingdigit[, parensfornegative[, groupdigits]]]])
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>
<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.
<li>{name} Brackets with a name. Placeholders are replaced by the value of the name in the argument object.
</ol>


FORMATDATETIME(date[, formatname])
== Example ==


FORMATNUMBER(expression[, fractionaldigits[,
<tabber>
JavaScript=
<syntaxhighlight lang="JavaScript">
guy = {first: "Eric", last: "Cartman"};


                leadingdigit[, parensfornegative[, groupdigits]]]])
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"}


FORMATPERCENT(expression[, fractionaldigits[,
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"})
</syntaxhighlight>
</tabber>


                leadingdigit[, parensfornegative[, groupdigits]]]])
== Output ==
<pre>
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
</pre>
</pre>


'''Description'''
[[Category:Language Reference]]
 
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. 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. The optional parameters, ''leadingdigit'', ''parensfornegative'', and ''groupdigits'', are numeric expressions or constants, see below. ''leadingdigit'' specifies whether a leading zero is printed for numbers with only fractional parts. ''parensfornegative'' specifies if negative values are to be printed with enclosing parentheses. ''groupdigits'' specifies if numbers are to be printed in groups using the systems group delimiter.
 
'''Table 11: Tristate values'''
 
{| class="wikitable"
|-
! Name !! Value !! Description
|-
| True || -1 || True
|-
| 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.
 
'''Table 12: formatname constants'''
 
{| class="wikitable"
|-
! Constant !! Value !! Description
|-
| vbGeneralDate || 0 || Short date, Long time
|-
| vbLongDate || 1 || Long date
|-
| vbShortDate || 2 || Short date
|-
| vbLongTime || 3 || Long time
|-
| vbShortTime || 4 || Short time
|}


'''Example'''
[[Category:Strings]]


<pre>
[[Category:BASIC Functions]]
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>
 
'''Output'''
<pre>
($3.50)
$123,456
8/18/1998 10:44 PM
August 18, 1998
-.142900
987,654.321
.70%
123456%
(''sample output is system dependant'')
</pre>

Latest revision as of 15:22, 24 July 2019

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:

  1. {} Empty brackets. Placeholders are replaced with arguments in the same order as they appear in the function call.
  2. {1] Brackets with a number. Placeholders are replaced by the argument number as it appears in the function call.
  3. {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