sprintf()

Formatted print utility

Syntax
sprintf(Format, Variable)

Name Description Range Type Required
Format Format of string in C language syntax "%d %f %g %e %s %c\n\t" string text yes
Variable Variable that is to be formatted   integer, real, complex, string or integer/real/complex array yes

Examples
iVal = 10

rVal = 10.23

cVal = 1\+j\*2

sVal = "one"

rA = makearray\(1, 1, 2.1, 3\)

cA = makearray\(2, 1\+j\*1, 2\+j\*2, 3\+j\*3\)

fmtI = sprintf("Integer value is %d", iVal)
returns text "Integer value is 10"
fmtR = sprintf("Real value is %g", rVal)
returns text "Real value is 10.23"
fmtC = sprintf("Complex value is (%g+j%g)", cVal)
returns text "Complex value is (1+j2)"
fmtS = sprintf("String value is %s", sVal)
returns text "String value is one"
fmtr_rA = sprintf("%g", rA)
returns text "1 2.1 3"
fmtr_cA = sprintf("%g+j%g", cA)
returns text "1+j1 2+j2 3+j3"

See Also

value()

Notes/Equations
  1. The sprintf() function is used to format a Simulator Expression variable into string or text format. It can be used to format data of integer, real, complex, string, and array types. The returned string text can then be printed in the data display or output to the console using the system function with an echo command.
  2. The sprintf() function is similar to the C function sprintf with certain restrictions. Only format %d, %f, %g, %e, and %s are supported. Only one variable can be formatted. For example, rVals=sprintf("%g %g", 10.1, 20.2) is not permitted.
 

Privacy Statement  | Terms of Use  | Legal | Contact Us  | © Agilent 2000-2008 

Contents
Additional Resources