1. Floating number converted to string R_S

1. Floating number converted to string R_S

1.1. Instruction Description

Convert the input floating-point number (IN) into a string of ssss bytes starting from address (OUT) according to the format mask (FMT). The last ssss+1th byte is represented by a 0 indicating the end bit.

Format Mask (FMT) assigns the precision after the decimal point, using dots or commas to represent the decimal point, as well as the length of the string.

The length of the output string is specified by the ssss field. 0, 1, or 2 byte sizes are invalid. The number of decimal places to the right of the output buffer is allocated by the nnn field. The valid range for the nnn field is 0 to 5. If a zero digit is assigned to the right of the decimal point, the value will not display the decimal point. If nnn is greater than 5, or if the length of the allocated output string is too small to store the converted value, the output string will be filled with ASCII space characters. Specify whether to use a comma (c=1) or a decimal point (c=0) as the separator between integers and decimals.  

The following figure also provides an example of a value in the format of: decimal point (c=0), with one digit to the right of the decimal point (nn=001), and the length of the output string is 6 characters (ssss=0110). The value at OUT is the length of the string stored in the next byte address.

Exchange example

图1 Exchange example

1.2. Attention

a) The OUT string (including the generated end bit) will overwrite all data of the original software component.

b) The encoding of the string is ASCII (ISO/IEC 646), please do not use other encoding methods such as UTF-8, Unicode, etc.

c) The real number format used by the CPU supports up to 7 significant digits. Attempting to display 7 or more significant digits will result in rounding errors.

1.3. The valid operands of the instruction

Input/Output Data Type operand Description
IN 32-bit real number D/K/FD, local variable (LF) input
FMT 16 bit unsigned integer D/CV/TV/AI/AO/K/H/V/Z/FD, bit composite word (X/Y/M/C/T/S), local variable (LW) Format
OUT 16 bit unsigned integer D/CV/TV/AO/V/Z, bit composite word (Y/M/C/T/S), local variable (LW) output

1.4. Example

Command table

NETWORK 000

LDP X000//String operations are time-consuming, so try to use edge conditions to trigger them.

R_S K3.141593 HFA D10//Convert the integer D0 to a string starting from D10, where c=1 (using dots), nn=2 (2 decimal places), ssss=15 (a 15 byte string)

RS

图2 RS