DADiSP Worksheet Functions > Function Categories > String Manipulation > NUM2STR

 

NUM2STR

Purpose:

Converts a number or series to a string with optional precision.

Syntax:

NUM2STR(val, format)

val

-

A real or series to convert to a string.

format

-

Optional. An integer or string. If an integer, the maximum number of significant digits. If a string, the format string as specified by SPRINTF.

Returns:

A string.

Example:

str1 = "The value if PI is " + num2str(pi);

str2 = "The value of PI is " + num2str(pi, 10);

str3 = "The value of PI is " + num2str(pi, "%1.7f");

 

str1 == "The value if PI is 3.14159"

str2 == "The value of PI is 3.141592654"

str3 == "The value of PI is 3.1415927"

Example:

s = num2str(rand(5));

viewtext(s)

 

Displays text similar to the following:

 

0.454054    0.423902    0.898038    0.535051    0.533219

0.083224    0.066347    0.770898    0.044221    0.962798

0.788690    0.084902    0.681326    0.503098    0.844935

0.448866    0.367351    0.258431    0.874538    0.508408

0.034455    0.462111    0.155004    0.399365    0.778100

Remarks:

NUM2STR uses the current default if format is unspecified.

 

The actual number of significant digits depends on the magnitude of the input value.

 

See SPRINTF for generic string formatting.

See Also:

DISP

NUMSTR

SETFORMAT

SETPRECISION

SPRINTF

STRCAT