lr_convert_double_to_double

Formats the string representation of a double value using a printf-style format specifier.

int lr_convert_double_to_double( char *source_param_name, char *format_string, char * target_param_name );

Arguments

NameComments
source_param_name The name of the parameter containing the double to be reformatted.
format_string A printf-style format specifier.
target_param_name The parameter to contain the reformatted string.

lr_convert_double_to_double formats the string representation of a double value using a printf-style format specifier. The target parameter is created if it does not exist.

The maximum length of the output string to be written to target_param_name is 63 characters. Create your format string accordingly.

If the input string is not a pure number string, as many characters as possible are converted. The rest are ignored. A string that does not begin with a character that can be converted causes an error.

For example:

  • “1234ABCDF” is converted to 1234.
  • “312.123.32.23123” is converted to 312.123 .
  • “MyProduct” and “ABC123PC” cause errors.

Return Values

This function returns LR_PASS (0) on success, and LR_FAIL (1) on failure.

Parameterization

Standard parameterization is not available for this function.

Example

In the following example, lr_convert_double_to_double converts the string representation of a double to several other string representations.


lr_save_string("1.0502731456E7","sourceParam");
lr_save_string("10062731.0","sourceParam2");

lr_convert_double_to_double("sourceParam","%.2f","outparam");
lr_output_message("[%s] converted to: [%s]",
lr_eval_string("{sourceParam}"),lr_eval_string("{outparam}"));

lr_convert_double_to_double("sourceParam","%.3f","outparam");
lr_output_message("[%s] converted to: [%s]",
lr_eval_string("{sourceParam}"),lr_eval_string("{outparam}"));

lr_convert_double_to_double("sourceParam","%.0f","outparam");
lr_output_message("[%s] converted to: [%s]",
lr_eval_string("{sourceParam}"),lr_eval_string("{outparam}"));

lr_convert_double_to_double("sourceParam2","%9.7E","outparam");
lr_output_message("[%s] converted to: [%s]",
lr_eval_string("{sourceParam2}"),lr_eval_string("{outparam}"));
Example: Output:
Action.c(9): [1.0502731456E7] converted to: [10502731.46] Action.c(12): [1.0502731456E7] converted to: [10502731.456] Action.c(15): [1.0502731456E7] converted to: [10502731] Action.c(18): [10062731.0] converted to: [1.0062731E+007]