FC_LrealToString

 

FC_LrealToString - General Information

Overview

Type:

Function

Available as of:

V1.0.3.0

Versions:

Current version

Task

Convert numerical values into a formatted string.

Description

The function converts any numerical value to a STRING with freely defined format. The format is specified in the input variables i_sFormat as follows:

i_sFormat = "bbSiiiii.fffffAaa"

bb is used to set the base of the number representation. Values in the range of 2..16 are allowed. If no value is given for bb, 10 is used as default value.

(Examples: 2=binary, 8=octal, 10=decimal, 16=hexadecimal)

S is used to represent the mathematical sign. If a base is entered, then the mathematical sign representation must also be specified. Otherwise, this entry may be dispensed with and "#" will be used as a default. As a basic principle, a minus sign will always precede negative values, independent of the format specification. In other respects, the following options exist for formatting:

o"#" - nothing precedes non-negative numbers.

o"-" - an empty space precedes non-negative numbers.

o"+" - a + precedes positive numbers, an empty space precedes 0.

Each i character before the decimal point represents a place preceding the decimal point in the output. This is used to input the minimum number of characters that are reserved for the whole number component and what should be included in the output when the numerical representation is shorter than that provided for in the format string. If i is a space, then a space is inserted at that position. If i is zero, then a zero will be inserted. Leading zeros may be implemented using this portion of the format input, or it can be assured that the decimal point is always at the same position from the left edge of the output string. If only a zero is specified, all places preceding the decimal point of the transferred LREAL are converted to a string.

The decimal point is only required when f characters are desired.

The f signs following the decimal point determine the number of spaces following the decimal point in the output. Each f represents one position following the decimal point. If the input value has more positions following the decimal point than the format provides for, the remainder will be deleted. If it has fewer, then it will be filled up according to f. If f is an empty space, then an empty space is put into that position. If f is zero, then a zero will be put there. If f is an underline, nothing will be entered. This input is used to either fix the number of positions after the decimal point or to determine the distance of the decimal point from the right edge.

Finally, A can be used to determine if the output has a fixed total length and if it is to be left or right justified or centered. Possible values are "L" for left justified, "R" for right justified or "C" to indicate the number centered.

The desired length of the output is determined by aa. If the output has more characters than are specified, the value to the right is filled out with empty spaces so that the numbers are displayed according to A.

If no adjustment is desired, simply do not specify any A or aa in the format string. But if one of the two values is specified, then the other must be specified as well.

Interface

Input

Data type

Description

i_sFormat

STRING[80]

Formatting the output

i_lrInput

LREAL

The value to be formatted

Output

Data type

Description

q_etDiag

GD.ET_Diag

General library-independent statement on the diagnostic.

A value not equal to ET_Diag.Ok corresponds to an diagnostic message.

q_etDiagExt

ET_DiagExt

POU-specific output on the diagnostic.

q_etDiag = ET_Diag.Ok -> Status message

q_etDiag <> ET_Diag.Ok -> Diagnostic message

Return Value

Data type

Description

STRING[80]

The value transferred at i_lrInput is converted to a STRING in the specified format and returned.

Diagnostic Messages

q_etDiag

q_etDiagExt

Enumeration value

Description

OK

Ok

0

Ok

LimitReached

LrealValueTooBig

298

LREAL value is too big

LrealValueTooBig

Enumeration name:

LrealValueTooBig

Enumeration value:

298

Description:

LREAL value is too big

Issue

Cause

Solution

-

An invalid value has been transferred to the i_lrInput input.

A value greater than or equal to -2 000 000 000.0 and smaller than or equal to 2 000 000 000.0 must be transferred at the i_lrInput input.

Ok

Enumeration name:

Ok

Enumeration value:

0

Description:

Ok

The conversion has been completed successfully.