Set the display format for cells in a vector spreadsheet view.
Syntax
vector_name.setformat format_arg
where format_arg is a set of arguments used to specify format settings. If necessary, you should enclose the format_arg in double quotes.
For vectors, setformat operates on all of the cells in the vector.
You should use one of the following format specifications:
g[.precision] | significant digits |
f[.precision] | fixed decimal places |
c[.precision] | fixed characters |
e[.precision] | scientific/float |
p[.precision] | percentage |
r[.precision] | fraction |
To specify a format that groups digits into thousands using a comma separator, place a “t” after the format character. For example, to obtain a fixed number of decimal places with commas used to separate thousands, use “ft[.precision]”.
To use the period character to separate thousands and commas to denote decimal places, use “..” (two periods) when specifying the precision. For example, to obtain a fixed number of characters with a period used to separate thousands, use “ct[..precision]”.
If you wish to display negative numbers surrounded by parentheses (i.e., display the number -37.2 as “(37.2)”), you should enclose the format string in “()” (e.g., “f(.8)”).
Examples
To set the format for all cells in the vector to fixed 5-digit precision, simply provide the format specification:
v1.setformat f.5
Other format specifications include:
v1.setformat f(.7)
v1.setformat e.5
Cross-references
See
Vector::setwidth,
Vector::setindent and
Vector::setjust for details on setting spreadsheet widths, indentation and justification.