Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

splitting percentages.... more help please

Kain Cleaver
Registered User
Join date: 24 Jan 2006
Posts: 178
01-07-2009 23:20
ok im a lil stumped.. im not the best at figuring out math stuff in scripting..and when i usually do find out how to do something im usualy taking a long way around..

ok.. so heres what im doing.. i need to find a way of taking a total of any amount.. (obviously smaller amounts like 1 - 10 may be more difficult.. ) and splitting it between a series of percentages...

how do i take a solid amount.. and divide it properly??

so.. a total pay in amount say is L$25

i want to divide it 7 ways..

50% first prize
25% 2nd
10% 3rd
5% 4th
3% 5th
4% owner take
3% host take

as i said im horrible with math can someone help me out
ab Vanmoer
Registered User
Join date: 28 Nov 2006
Posts: 131
01-08-2009 00:58
The basic percentage is fairly straight forward, if x is the percentage and total is the amount to split, then split=(x*total)/100;

for example, 50% of L$25 then
split=(50*25)/100
split=L$12.5

The problem comes in because there are no cents in L$, so in this case you could round down to L$12. but this becomes problematic when you get down to smaller percentages, eg 3% of 25 is L$0.75 which would round down to zero.

The only way around this, depending on our application, would be to accumulate the total until it reaches a larger value before splitting it, for instance L$100 would work.