# calculate the ratio between the death and kills

Comments in 'Plugin Development' started by Praxthisnovcht, Feb 3, 2015.

1. Offline

### PraxthisnovchtNotable MemberPlugin Developer

Joined:
Mar 10, 2014
Posts:
697
Plugins:
4
Minecraft User:
Yo guys,

how could thy calculate a ratio between two things?
like the Kills and Death

??
2. Offline

### LDXNotable MemberPlugin Developer

Joined:
Oct 2, 2013
Posts:
1,395
Plugins:
14
You could subtract the deaths from the kills, or you could do what I do. A kill is worth 3 points and a death is worth 1 point.
3. Offline

### Tethered_Active MemberPlugin Developer

Joined:
Jun 24, 2014
Posts:
178
Plugins:
2
Minecraft User:
You'd probably have to store the number of kills and deaths in a database of some type and constantly keep an updated number for the ratio (kills/deaths and maybe rounded to the tenths place)
4. Offline

### PraxthisnovchtNotable MemberPlugin Developer

Joined:
Mar 10, 2014
Posts:
697
Plugins:
4
Minecraft User:
How to have killed one gives 3 points? xD

I want to make it simple: p
5. Offline

### LDXNotable MemberPlugin Developer

Joined:
Oct 2, 2013
Posts:
1,395
Plugins:
14
PHP:
``` \$points = \$kills * 3 + \$deaths; ```
Praxthisnovcht likes this.
6. Offline

### PraxthisnovchtNotable MemberPlugin Developer

Joined:
Mar 10, 2014
Posts:
697
Plugins:
4
Minecraft User:
7. Offline

### PEMapModderNotable MemberPlugin Developer

Joined:
Oct 9, 2013
Posts:
7,230
Plugins:
11
Minecraft User:
Define the word ratio, and you would find that you are looking for kills divided by deaths. So \$kills / \$deaths of course.
iJoshuaHD, iksaku and Falk like this.
8. Offline

### FalkStaff MemberGlobal Moderator

Joined:
Sep 2, 2013
Posts:
1,699
Plugins:
22
Minecraft User:
But you will want to truncate or round that to a set amount of decimal places.
iksaku likes this.
9. Offline

### PEMapModderNotable MemberPlugin Developer

Joined:
Oct 9, 2013
Posts:
7,230
Plugins:
11
Minecraft User:
PHP:
``` /** @param int \$kills @param int \$deaths @param int \$digits default 3 decimal places @return string */function getKdRatio(\$kills, \$deaths, \$digits = 3){  if(\$deaths === 0) return "N/A";  \$ratio = (string) round(\$kills / \$deaths, \$digits);  return rtrim(\$ratio, " 0.");} ```
10. Offline

### PraxthisnovchtNotable MemberPlugin Developer

Joined:
Mar 10, 2014
Posts:
697
Plugins:
4
Minecraft User:

thank you !