mirror of
https://github.com/processing/processing4.git
synced 2026-02-12 10:00:42 +01:00
88 lines
1.9 KiB
XML
88 lines
1.9 KiB
XML
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
|
<root>
|
|
<name>nfs()</name>
|
|
|
|
<category>Data</category>
|
|
|
|
<subcategory>String Functions</subcategory>
|
|
|
|
<usage>Web & Application</usage>
|
|
|
|
<example>
|
|
<image></image>
|
|
<code>
|
|
int a=200, b=-40, c=90;
|
|
String sa = nfs(a, 10);
|
|
println(sa); // prints " 0000000200"
|
|
String sb = nfs(b, 5);
|
|
println(sb); // prints "-00040"
|
|
String sc = nfs(c, 3);
|
|
println(sc); // prints " 090"
|
|
|
|
float d = -200.94, e = 40.2, f = -9.012;
|
|
String sd = nfs(d, 10, 4);
|
|
println(sd); // prints "-0000000200.9400"
|
|
String se = nfs(e, 5, 3);
|
|
println(se); // prints " 00040.200"
|
|
String sf = nfs(f, 3, 5);
|
|
println(sf); // prints "-009.01200"
|
|
</code>
|
|
</example>
|
|
|
|
<description>
|
|
Utility function for formatting numbers into strings. Similar to <b>nf()</b> but leaves a blank space in front of positive numbers so they align with negative numbers in spite of the minus symbol. There are two versions, one for formatting floats and one for formatting ints. The values for the <b>digits</b>, <b>left</b>, and <b>right</b> parameters should always be positive integers.
|
|
</description>
|
|
|
|
<syntax>
|
|
nfs(intValue, digits)
|
|
nfs(floatValue, left, right)
|
|
</syntax>
|
|
|
|
<parameter>
|
|
<label>intValue</label>
|
|
<description>int: the number to format</description>
|
|
</parameter>
|
|
|
|
<parameter>
|
|
<label>digits</label>
|
|
<description>int: number of digits to pad with zeroes</description>
|
|
</parameter>
|
|
|
|
<parameter>
|
|
<label>floatValue</label>
|
|
<description>float: the number to format</description>
|
|
</parameter>
|
|
|
|
<parameter>
|
|
<label>left</label>
|
|
<description>int: number of digits to the left of the decimal point</description>
|
|
</parameter>
|
|
|
|
<parameter>
|
|
<label>right</label>
|
|
<description>int: number of digits to the right of the decimal point</description>
|
|
</parameter>
|
|
|
|
|
|
<returns>String or String[]</returns>
|
|
|
|
<related>
|
|
nf()
|
|
nfp()
|
|
</related>
|
|
|
|
<availability>1.0</availability>
|
|
|
|
<type>Function</type>
|
|
|
|
<partof>Core</partof>
|
|
|
|
|
|
<level>Extended</level>
|
|
|
|
|
|
|
|
|
|
|
|
</root>
|