A more elegant way to add interest?

I am wondering if there is a more elegant way to add interest. For example, if I wanted to add 12% of the value of $a to $a , I do:

 $a = 100; $a = $a + (($a / 100) * 12); 

Which gives me 112 as a new meaning, of course. But I cannot help but feel that this is too verbose, and there should be a better way to make a percentage addition.

I tried:

 $a = $a + 12%; 

But, as expected, this will not work. Before I start looking at a function myself to make it easier, is there an existing way to do this?

+4
source share
3 answers

Why not $a *= 1.12; ?

"Percentage" comes from the Latin "percent" or "per hundred." One percent is 1/100. Thus, twelve percent are 0.12 - 12 hundredths.

+14
source

All you have to do is:

 $a *= 1.12; 
+6
source

Here is how I do it:

 $percent = 10; $price *= (1 + $percent / 100); 
+4
source

All Articles