KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Number variables typed as “Integer” will have decimal values rounded
PRODUCT: 4D | VERSION: 20 | PLATFORM: Mac & Win
Published On: December 11, 2024

Typically, variables that contain number values can have their type declared as either “Integer” or “Real”. If a variable is declared as Integer type, and then is assigned a decimal value, it will be rounded either down or up, depending on the value. For example, consider the following:

var $num1; $num2; $num3 : Integer

$num1:=4.45 // value: 4
$num2:=4.5 // value: 4
$num3:=4.51 // value: 5

All 3 variables are typed as Integer type, and then assigned different decimal values. The values for $num1 and $num2 will be rounded down to 4, because they were assigned values less than or equal to 4.5. The variable $num3 will have value 5, because it was assigned a value greater than 4.5. Note that if rounding is not intended, use the Real type instead.