Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Transform a type of variable that is Currency into Type Integer

Posted on 2003-03-20
5
Medium Priority
?
256 Views
Last Modified: 2010-04-04
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
0
Comment
Question by:Fredy992
5 Comments
 

Expert Comment

by:mertdogan
ID: 8173065
You can use this code and your code will be corrected:

Y:=Integer(X);

But it's not safety. You can use direct convert methods that defined in sysutils.
0
 

Expert Comment

by:Imagine
ID: 8173100
A fine solution (and save) is

y := trunc(x);

this always works :)
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 8173122
or also

y := round(x);

:-))
0
 

Accepted Solution

by:
mertdogan earned 360 total points
ID: 8173132
Additionally you can use this procedure

Function CurrencyToInteger(CurType: Currency): Integer;
var
  i: integer;
  j: Comp;
begin
CurrencyToComp(CurType, j);
Result:=StrToInt(FloatToStr(j));
end;
0
 
LVL 17

Expert Comment

by:geobul
ID: 8177021
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
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…

571 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question