Jump to content
taariq

Currency Calculations

Recommended Posts

Good day
Plz note I am a newbie to Delphi and still learning but enjoying it...

 

I need help with calculations please...

 

I got total sum via database by using the following code that is working...

 

dmuse.dmDBuse.FDQueryMaterialTotal.Open('SELECT SUM(COST) AS TC FROM MATERIAL WHERE ORDERNO=:d',[dbOrderNo.Text]);
Showmessage(format( 'Total for Material OrderNo %s is %m',[dbOrderNo.text,dmuse.dmDBuse.FDQueryMaterialTotal.FieldbyName('TC').asCurrency]));
tMaterial.text:=Format('%m',[dmuse.dmDBuse.FDQueryMaterialTotal.fieldbyName('TC').asCurrency]);

 

dmuse.dmDBuse.fdQueryTraveling.Open('SELECT SUM(COST) AS TC FROM TRAVELING WHERE ORDERNO=:d',[dbOrderNo.Text]);
Showmessage(format( 'Total for Traveling OrderNo %s is %m',[dbOrderNo.text,dmuse.dmDBuse.fdQueryTraveling.FieldbyName('TC').asCurrency]));
tTraveling.text:=Format('%m',[dmuse.dmDBuse.fdQueryTraveling.fieldbyName('TC').asCurrency]);

 

But here is my issue - trying to add the two values together

 

Code I tried but get error -
image.png.122147abf0241d124163876c65845104.png

 

Code I am using...

procedure TForm1.Button2Click(Sender: TObject);
var  tMaterial, tTraveling, tTotalCost: Currency ;
 usSet : TFormatSettings;
begin
  usSet:=TFormatSettings.Create('EN_US');

  tMaterial :=  StrToCurr (lbMaterial.Caption,usSet) ;
  tTraveling :=  StrToCurr (lbTraveling.Caption,usSet) ;


  tTotalCost := tMaterial + tTraveling;

  tProjectCosting.text := CurrToStrF(tTotalCost, ffCurrency, 2);

end;

 

Please help

Thank you

Share this post


Link to post

Thanks for quick reply
 

Do you know how to use the debugger to inspect vakues being passed to StrToCurr?  > this will be so helpful - how do I inspect error

 

Thank you

Share this post


Link to post

Good day
I got a nice google video on how to run and use debugger...

 

What I see now ...but still don't understand
image.thumb.png.3525bfb1c9d9e934eecd575123ddd5d6.png

Share this post


Link to post

Set a break point on the line where the error occurs. When the code breaks there inspect the value of the argument passed to StrToCur. 

Share this post


Link to post

I would first of all use the corresponding components on the form. If I have a Currency type, I wouldn't use a component that works with text! It's best not to use the StrToCurr() and CurrToStr() functions at all.

Share this post


Link to post

"Material is not a valid floating point value" 

 

Ask yourself why you are trying to convert the text Material to a numeric value. Do you know why yet?? 

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×