- Type of reals
- Default value
- Binary coding of reals
- Thousand separator
- Problems of precision with the reals
- Specific features of PHP
- Differences with WINDEV/WEBDEV 5.5
Two types of reals are available in WLanguage:
A "Real" variable that is declared but not initialized is equal to 0.
Binary coding of reals
All the reals contain the same number of significant digits (15).
If the result of a calculation performed on reals
involves more than 15 significant digits, this result will be automatically rounded to 15 significant digits. For a better precision, use the Currency
You can use spaces and underscore characters to separate thousands in numbers. For example:
num1 is real
num1 = 123 456.478
num2 is real
num2 = 7_014.478
Problems of precision with the reals
The operations performed with the "real" types are not precise because of the computing representation of reals.
Two reals that are equal mathematically speaking are not necessarily equal computer-wise and the ">", "<" or "=" operators can return results that are "false" mathematically speaking.
To fix some of these problems:
- the "=" operator is accurate to 10e-6 on the reals. Therefore, for two reals that are relatively close, the "=" and ">" operators (or "=" and "<") can return True for the same values.
- the conversion of real values into string uses a complex algorithm. This is why, in most cases, the display by trace is correct.
To avoid these problems, you must use the Currency
type that is using an exact memory representation.
Specific features of PHP
The numbers (real, integer, currency, numeric) cannot exceed 14 significant digits in PHP. If they exceed this limit, they are rounded to 14 digits.
This page is also available for…