svasilakos
asked on
How to I define a number as a percentage
This seems kind of silly but I can't find anything on it and I'm just a beginner. I need to perform a simple calculation. Doing the calc is not the problem but I can figure out how to define a value as a percentage.
Total = (value1 + value2) * buyrate;
I just need the value of buyrate to = 3.99% so I can multiply BY a percentage.
Total = (value1 + value2) * buyrate;
I just need the value of buyrate to = 3.99% so I can multiply BY a percentage.
Variable as percentage is double or float ...
for example
double myNum = 3.99;
for example
double myNum = 3.99;
double buyRate = 3.99;
Total = (value1 + value2) * buyRate / 100;
I don't think you bother about %. If you need to display it, just add % after that number.
Total = (value1 + value2) * buyRate / 100;
I don't think you bother about %. If you need to display it, just add % after that number.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
It's not the display that is causing me problem it's how to do the calculation in the code file
Here is a subset from my code
double buyrate = 3.99;
double totcommish = 0;
lessbrate = (advamount + feeamount) * buyrate;
advamount and feeamount are define elsewhere ( these are sums of some data I am retriving from a db). Obviously double buyrate; is wrong becuase I do not want to multiply by 3.99 , I want to multiply by 3.99%.
Here is a subset from my code
double buyrate = 3.99;
double totcommish = 0;
lessbrate = (advamount + feeamount) * buyrate;
advamount and feeamount are define elsewhere ( these are sums of some data I am retriving from a db). Obviously double buyrate; is wrong becuase I do not want to multiply by 3.99 , I want to multiply by 3.99%.
Heh.. that's why Tim and I both proposed divide by 100!
Ok.. just wondering: How come my answer is not accepted ? :D
ASKER
Sorry, all your respones came very quickly. I saw Tim's before I saw your. You guys posted within miliseconds of each other
<%=Total & "%" %>