Hey Folks,

Just starting out with vb.net and am struggling with an equation

I have a fixed percentage 0.3%
I need to multiply this by a number of months which varies 1 to 12

Having done this I need to add the percentage to a pre-determined number

so as an example

£300 + (0.3 * 10)

I can get the 3% (0.3 * 10)

But when I add this to the existing number (£300) it equals £303 not £309 which is what it should equal.

Can anyone advise the way of adding a percentage as appose to just another number? This also need to allow for -percentages i.e. -3%

The equation I am using is below and I appreciate there is nothing to set decTotalPercentage as an actual percentage but that's because I am stumped...

decTotalPercentage = decPercentage * intMonths
decFinalPercentage = decMoney + decTotalPercentage

Recommended Answers

All 4 Replies

Your formula for percentage is wrongly stated, since you are multiplying the percentage to the months and adding it to the total, so the total is not actually participating in the percentage.

Besides, your percentage conversion is wrong. Remember 0.3% != 0.3 but 0.3% = 0.003 .

So, that said, your formula should be 300 + (0.003 * 10) the way you stated it. And, to take the percentage of the amount you want to operate, change the '+' for an '*', and you're set. Like this:

300 * (0.003 * 10)

So, in the end, your formulas are as follows:

decTotalPercentage = decPercentage / 100 * intMonths
decFinalPercentage = decMoney * decTotalPercentage

In which, if you replace and resume, it is

decFinalPercentage = decMoney + decMoney * (decPercentage / 100 * intMonths)
decFinalPercentage = 300 + 300 * (0.3 / 100 * 10)

And the result is 309

Oh nice one thanks, was programming all day yesterday and this just got the better of me. will give this a go thanks again....

Cool changed it slightly:

decFinalPercentage = decMoney + decMoney * (decTotalPercentage / 100)

This works a treat thanks a lot you're a star...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.