Michael Van Canneyt wrote:
On Tue, 1 Jan 2008, Lee Jenkins wrote:
Michael Van Canneyt wrote:
On Tue, 1 Jan 2008, Lee Jenkins wrote:
I have a method of a class such as:
function TMyObject.Test(ACurrency: Currency)
begin
// do some stuff
end;
Now, I'll call this method like:
MyObject.Test(0.23);
The problem is that inside the Test method, the current type is converted
to
an integer like 2300.
How is this done ?
Currency is actually an int64 type, with a scale factor of 10.000, so this
is normal. What is not normal is that you see it in your code.
Michael.
That is what is shows in the IDE info tip when hovering the mouse cursor over
the variable. Even more odd is that the variable's value is what the tool tip
displays, the whole integer and not the fractional value passed in.
That is an IDE error.
I tried assigning the value to a variable and passed that into the method
instead of passing a literal just in case, but the result is the same.
Can you show the code ? Currency has been working just fine as far as I know;
this is the first time I heard that there would be some error.
Michael.
Yes, odd because I have used currency before with no problems.
Here is the method being called. As of now, I have changed the Currency types
to Double and everything works. Just changed it back to Currency here for the
list's benefit.
function TLevy.CalculateLevy( AmountToLevy: Currency) : Currency;
var
lResult: Currency;
begin
result := 0;
lResult := AmountToLevy * FLevyValue;
result := self.GetRoundedValue(FRoundingType, lResult);
end;
function TLevy.GetRoundedValue( ARoundType: TLevyRounding;AAmount: Currency
) : Currency;
begin
case ARoundType of
lrRndDownBy01: result := Double(Floor(100 * AAmount) / 100);
lrRndUpBy01: result := Double(Ceil(100 * AAmount) / 100);
lrRndDownBy05: result := Double(Floor(20 * AAmount) / 20);
lrRndUpBy05: Result := Double(Ceil(20 * AAmount) / 20);
lrRnddownBy25: result := Double(Floor(4 * AAmount) / 4);
lrRndUpBy25: result := Double(Ceil(4 * AAmount) / 4);
lrBankers: result := Round(AAmount);
end;
end;
The method gets called from here, in this test case.
procedure TTestLevy.LevyCalculate;
var
lLevy: TLevy;
lAmount: Currency;
ToLevy: Currency;
begin
// Note: This is not a permanent test case. More extensive
// testing will be here. Just a few simple test for now.
// Lee Jenkins, 12/25/2007
lLevy := TLevy.CreateNew('','');
try
// test round .25
ToLevy := 25.00;
lLevy.LevyType := ltTax;
lLevy.LevyValue := 0.05;
lLevy.RoundingType := lrRndUpBy25;
lAmount := lLevy.CalculateLevy(ToLevy);
AssertTrue('RoundDown did not calculate correctly', lAmount = 1.25);
// test round down to .05
ToLevy := 15.35;
lLevy.RoundingType := lrRndDownBy05;
lLevy.LevyValue := 0.07;
lAmount := lLevy.CalculateLevy(ToLevy);
AssertTrue('RoundUp did not work correctly', lAmount = 1.05);
// Test round up to .05
ToLevy := 15.35;
lLevy.RoundingType := lrRndUpBy05;
lLevy.LevyValue := 0.07;
lAmount := lLevy.CalculateLevy(ToLevy);
AssertTrue('Round Down did not work.', lAmount = 1.10);
finally;
lLevy.free;
end;
end;
--
Warm Regards,
Lee
"If I don't see you around here, I'll see you around, hear?"
_________________________________________________________________
To unsubscribe: mail [EMAIL PROTECTED] with
"unsubscribe" as the Subject
archives at http://www.lazarus.freepascal.org/mailarchives