Stephen Selvey
Stephen Selvey

Reputation: 393

Divide to numbers but keep decimal?

How to divide two numbers but keep the decimal point.

Also I need to turn the decimal point into a percentage...ie .25 to 25%

tried $set ($percent = $a / $b) In this case $a = 10, $b = 40.

#set($percent = $totalSponsored / $totalAppliesAllJobs)

Upvotes: 1

Views: 420

Answers (3)

Charan Narukulla
Charan Narukulla

Reputation: 11

#set($percent = (($totalSponsored*1.0) / ($totalAppliesAllJobs*1.0))*100)

In the above way it will become decimal/decimal which gives the ratio. Multiple it with 100 for percentage.

Upvotes: 0

Stephen Selvey
Stephen Selvey

Reputation: 393

I answered this using:

set($percent = $a * 100 / $b)

Upvotes: 0

Jari
Jari

Reputation: 39

double result = (double) number1 / (double) number2 * 100.0

The result variable now contains the percentage.

Upvotes: -1

Related Questions