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

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 883
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

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