Floating-point (Single, Double, Extended)
The default value for the floating-point data type is zero (0).
Float is a term that is used to represent floating point values, which are numbers that have any number of decimal places. Examples are 9.3, or 87.34567, or 3,567.36.
While a floating point number is referred to within Statelake functions using the keyword float, there is no data type called float - the data type Single, Double or Extended must be used.
Single data type uses only 4 bytes to store the mantissa of the float number in scientific notation, which determines the precision and storage size.
Double should be used for high accuracy operations, but Extended should be used for very high accuracy operations.
A Double data type variable can store a number between -5.0 x 10^324 and 1.7 x 10^308. These are extremely large negative and positive numbers - for instance, 1.7 x 10^308 equates to 1.7E308 or 170 followed by another 306 zeros and then a decimal point.
If a field within a DB Definition or File Definition is specified as Float then it may require a display format for it to be correctly saved to the database or file with the correct number of decimal places.
Use the display format #0.00 to display as 2 decimal places. For more information regarding the formatting of floating-point numbers, please refer to FormatFloat for information regards the FormatFloat function, and Format Specifiers for a list of available formats.
An Extended variable is used for scientific type data and can store an even larger number between -3.6 x 10^4951 and 1.1 x 10^4932. Again, these are humungous numbers.
If you try to store a number in a data type that is unable to fit that number you will receive an Overflow Error.
Declaration: var myvariable : single;
var myvariable : double;
var myvariable : extended;
A stand-alone example of these follows -
procedure
ScriptEvent (
var
Value : variant);
var
mynum :
single
;
myvariable :
double
;
thisvariable :
extended
;
begin
mynum :=
0.2
;
LogInfo(
'Howdy. The value of mynum is '
+FloatToStr(mynum));
myvariable :=
123.45
;
LogInfo(
'Howdy. The value of myvariable is '
+FloatToStr(myvariable));
thisvariable :=
901345.627498
;
LogInfo(
'Howdy. The value of thisvariable is '
+FloatToStr(thisvariable));
end
;