This reference is for Processing 3.0+. If you have a previous version, use the reference included with your software in the Help menu. If you see any errors or have suggestions, please let us know. If you prefer a more technical reference, visit the Processing Core Javadoc and Libraries Javadoc.

Name

nfp()

Examples
int a=200, b=-40, c=90; 
String sa = nfp(a, 10); 
println(sa);  // Prints "+0000000200" 
String sb = nfp(b, 5); 
println(sb);  // Prints "-00040" 
String sc = nfp(c, 3); 
println(sc);  // Prints "+090" 
 
float d = -200.94, e = 40.2, f = -9.012; 
String sd = nfp(d, 10, 4); 
println(sd);  // Prints "-0000000200.9400" 
String se = nfp(e, 5, 3); 
println(se);  // Prints "+00040.200" 
String sf = nfp(f, 3, 5); 
println(sf);  // Prints "-009.01200" 
Description Utility function for formatting numbers into strings. Similar to nf() but puts a "+" in front of positive numbers and a "-" in front of negative numbers. There are two versions: one for formatting floats, and one for formatting ints. The values for the digits, left, and right parameters should always be positive integers.
Syntax
nfp(num, digits)
nfp(nums, digits)
nfp(nums, left, right)
nfp(num, left, right)
Parameters
num float, or int: the number to format
digits int: number of digits to pad with zeroes
nums float[], or int[]: the numbers to format
left int: the number of digits to the left of the decimal point
right int: the number of digits to the right of the decimal point
ReturnsString or String[]
Relatednf()
nfs()
nfc()
Updated on July 4, 2018 11:56:43am EDT

Creative Commons License