%FLOAT (Convert to Floating Format)

%FLOAT(numeric or character expression)

%FLOAT converts the value of the expression to float format. This built-in function may only be used in expressions.

If the parameter is a character expression, the following rules apply:
  • The sign is optional. It can be '+' or '-'. It must precede the numeric data.
  • The decimal point is optional. It can be either a period or a comma.
  • The exponent is optional. It can be either 'E' or 'e'. The sign for the exponent is optional. It must precede the numeric part of the exponent.
  • Blanks are allowed anywhere in the data. For example, ' + 3 , 5 E 9' is a valid parameter.
  • If invalid numeric data is found, an exception occurs with status code 105.

For more information, see Conversion Operations or Built-in Functions.

Figure 1. %FLOAT Example
 *..1....+....2....+....3....+....4....+....5....+....6....+....7...+....
D*Name++++++++++ETDsFrom+++To/L+++IDc.Keywords+++++++++++++++++++++++++
D p1              s             15p 0 inz (1)
D p2              s             25p13 inz (3)
D c15a            s             15a   inz('-5.2e-1')
D c15b            s             15a   inz(' + 5 . 2 ')
D result1         s             15p 5
D result2         s             15p 5
D result3         s             15p 5
D result4         s              8f
 /FREE
 // using numeric parameters
    result1 = p1 / p2;          //  "result1" is now  0.33000.
    result2 = %float (p1) / p2; //  "result2" is now  0.33333.
    result3 = %float (p1 / p2); //  "result3" is now  0.33333.
   result4 = %float (12345);   //  "result4" is now 1.2345E4
 // using character parameters
   result1 = %float (c15a);    //  "result1" is now -0.52000.
   result2 = %float (c15b);    //  "result2" is now  5.20000.
   result4 = %float (c15b);    //  "result4" is now  5.2E0
 /END-FREE