Fredy992
asked on
Transform a type of variable that is Currency into Type Integer
I have to variables
X : Currency; X that is currency.
Y : Integer; Y tha is Integer.
when i put ( Y := X ) i get "Imcompatible types: "Currency" and "Integer".
how do i make the Currency to Integer. Please somone Help
X : Currency; X that is currency.
Y : Integer; Y tha is Integer.
when i put ( Y := X ) i get "Imcompatible types: "Currency" and "Integer".
how do i make the Currency to Integer. Please somone Help
A fine solution (and save) is
y := trunc(x);
this always works :)
y := trunc(x);
this always works :)
or also
y := round(x);
:-))
y := round(x);
:-))
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Hi,
Just my 2 cents:
Currency type variables contain real numbers. Converting them to integer numbers will cut, truncate or round their values throwing the fractional parts away. How will you do this depends on what you want to achieve. Ask yourself the following questions and let us know the answers.
- do you need the integer part only (regardless of the fractional part)?
- do you need to round the integer part depending on the fractional part (if >= 0.50 then +1 to the result)?
- how the negative values have to be processed?
Regards, Geo
Just my 2 cents:
Currency type variables contain real numbers. Converting them to integer numbers will cut, truncate or round their values throwing the fractional parts away. How will you do this depends on what you want to achieve. Ask yourself the following questions and let us know the answers.
- do you need the integer part only (regardless of the fractional part)?
- do you need to round the integer part depending on the fractional part (if >= 0.50 then +1 to the result)?
- how the negative values have to be processed?
Regards, Geo
Y:=Integer(X);
But it's not safety. You can use direct convert methods that defined in sysutils.