3.5.5.8 Text/Format

Description

Text function and Format function are equivalent except the default format used when the optional parameter fmt$ is missing, see the details in the Parameters section below. Please note that Text function is accessible from Set Column Value: F(x) menu while Format is not. However, both work via LabTalk script. If you are using version 9.1 or later, we advise using the Text function.

Text and Format convert double to string using one of these LabTalk formatting options.

Syntax

string dataString = Text(double d[, string fmt$])$
string dataString = Format(double d[, string fmt$])$

Parameters

d

A numeric of type double.

fmt$

A string specifying the output format. Option fmt$ formats output and will take these values. If fmt$ is not specified, Text function will use the column's format, while Format function will use Origin's global setting (which can be found by Preference: Option - Numeric Format). If fmt$ is set to the empty string "", both functions will use @SD significant digits, where @SD is a system variable (whose current value can be obtained by entering @SD=; in the Script Window). For instance, the value "*3" for the string fmt$ will yield 3 significant digits in the returned string. Use "*" to use Origin's global setting.

Return

Return the numeric data as a string in the format specified by fmt$.

Examples

// specifying 3 significant figures
string yy$=Text(2.01232, "*3")$;  
yy$=; // will return 2.01
// convert input numeric into engineering format, with 3 significant figures
string str$=Format(123000, "E*3")$;
str$=; //will return 123k
@SD=;  // get the current value stored in @SD
@SD=2; // reset the value in @SD to 2

// call text using the system default, @SD
string yy$=Text(2.456789, "")$;  
yy$=; // returns YY = 2.5
// convert date(d/mm/yyyy) to string in U.S. Regional settings format.
string yy$=Text(Date(7/10/2014),D1)$;
yy$=; // returns yy = Thursday, July 10, 2014