No, it's right.
Both "3" and "2" are integers, so the result is an integer. If you don't want an integer result you must cast it, or otherwise coerce the expression type.
Here is a simple script showing the processes:
code:
$iInteger=3
$dDouble=3.0
$vVariant=3/2 "Calculation using integer expression=" $vVariant ?
$vVariant=3.0/2 "Calculation using double expression=" $vVariant ?
$vVariant=$iInteger/2 "Calculation using integer=" $vVariant ?
$vVariant=$dDouble/2 "Calculation using double=" $vVariant ?
The results are as expected:
quote:
Calculation using integer expression=1
Calculation using double expression=1.5
Calculation using integer=1
Calculation using double=1.5
Interestingly "0.0+$a/$b" won't work. Due to operator precedence, "$a/$b" is evaluated first, and as an integer expression will result in "1". Adding 0.0 to it will have no effect.
You will need to use parentheses to change the precedence so that it becomes "(0.0+$a)/$b", or use a high precedence order operator like "1.0*$a/$b".
Using "1.0 * expression" is a good standard way of casting the expression to double, as KiXtart doesn't support true casting.
Unfortunately CDBL(3/2) results in an answer of "1", which is counter-intuitive. This is because the expression itself is an integer expression and is evaluated before being passed to the CDBL() function. A better solution would have been "C" type casting. Using this the expression becomes "(cdbl) $a/$b", which forces the expression to the correct type.
[ 13 June 2002, 13:51: Message edited by: Richard Howarth ]