dpValToString()
This function converts the value specified in val into a string, with the format string of the data point element dp being used. If anytype is a dyn, then this function returns a dyn_string as the result.
Synopsis
string dpValToString(string dp,anytype val[,bool unit=false]);
or
dyn_string dpValToString(string dp,dyn_anytype val[,bool
unit=false]);
Parameters
Parameter | Meaning |
---|---|
dp | data point |
val | any data type |
unit | true = The unit is appended to the formatted string. |
Return Value
This function returns either a string (formatted value with max. 1024 characters!) or a dyn_string (formatted values with max. dyn x 1024 character!).
Errors
Errors can be retrieved with getLastError(). An error message is issued in the event of incorrect or missing arguments (for example, incorrect type, missing data point)!
Description
The format string entered is not checked to determine whether it matches the data type. It is the responsibility of the user to enter the format correctly. For example the format or unit for a datatype struct makes no sense.
If an incorrect format string (i.e. one that does not correspond to the data type) is entered, this may result in output that is different from the original value. The possible formats can be found in the description of fprint().
If there is no format string, the return value of dpValToString() is a string in the format of the value.
Example
string x; float y = 1.23; x = y; // corresponds to x = dpValToString(dp, y) //if the format of dp is an empty string //x = "1.23" |
If you specify true as the 3rd parameter, the unit (if present) is appended to the formatted string.
Example
main()
{
string comout;
float val = 1.23;
comout = dpValToString("mld_float.", val, 1);
/* comout="001.23 liter" if format ="%6.2f" and unit ="Liter"
is. */
}
Examples for using different format strings you will find in the chapter sprintf().
Assignment
Data point functions, Strings
Availability
CTRL