• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 904
  • Last Modified:

How to multiply COleCurrency with float?

I would like to multiply a COleCurrency object with a float object and have the result as COleCurrency. What I've did is,

COleCurrency loanAmount(100,0);
float interest = 6.75;
COleCurrency totalLoanAmount = loanAmount + (loanAmount * interest / 100);

I got the warning "conversion from 'float' to 'long', possible loss of data"  when I compile. True enough, the result I obtained was multiplication with 6 and not 6.75.

Would like help on the correct method to do it.

Thank you.





 

Eg.,

COleCurrency loanAmount = 1000.00;
float interest = 6.79;

0
rayocs
Asked:
rayocs
  • 4
  • 2
1 Solution
 
mahesh1402Commented:
Why you cant use ColeCurrency instead of float ?

like :

COleCurrency loanAmount(100,0);
COleCurrency interest(6,75);
COleCurrency totalLoanAmount(00,00);

totalLoanAmount = loanAmount + (loanAmount * interest / 100);

-MAHESH
0
 
mahesh1402Commented:
it seems COleCurrency not support * + operators..

you may try converting that to float using atof :

   COleCurrency loanAmount(100,0);
   float interest = 6.75;
   float  totalLoanAmount = (float)atof(loanAmount.Format()) + (float)(atof(loanAmount.Format())  * interest / 100);

-MAHESH
0
 
rayocsAuthor Commented:
Yes, I might be able to do that. However, I need the final result to be a COleCurrency object. How can I do the conversion? Ie. from float to COleCurrency.
0
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

 
mahesh1402Commented:
>>I need the final result to be a COleCurrency object

Check if you can set using COleCurrency::SetCurrency().. you may use modf() function from math.h to separate integer and fraction parts.

-MAHESH
0
 
mahesh1402Commented:
e.g. this should work :

   COleCurrency loanAmount(100,0);
   float interest = 6.75;
   float  totalLoanAmount = (float)atof(loanAmount.Format()) + (float)(atof(loanAmount.Format())  * interest / 100);


   COleCurrency amtLoan;
   double ipart;
   double fract=modf(totalLoanAmount,&ipart);

   amtLoan.SetCurrency((long)ipart,(long)(fract*1000));


you need to include math.h in order to use modf().

-MAHESH
0
 
rayocsAuthor Commented:
It works well. Thanks Mahesh.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now