Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Finding a percent

Smithy Zeno
ownes 9 pet cacti
Join date: 3 Aug 2006
Posts: 52
04-24-2008 16:14
Hey all,
I have the following code:

CODE

percent_done = (integer)(time*0.01) * (current_length);


This is supposed to get the (integer)'percent_done', as time being the 'time' in seconds into the song and the 'current_length' being the total length in seconds of the song. This doesn't return the integer correctly, and I was wondering if someone could help me out. Thanks.
_____________________
-Smithy
Darien Caldwell
Registered User
Join date: 12 Oct 2006
Posts: 3,127
04-24-2008 16:17
I think you want:

CODE

percent_done = (integer) (time/current_length)*100;
_____________________
Smithy Zeno
ownes 9 pet cacti
Join date: 3 Aug 2006
Posts: 52
04-24-2008 16:53
Thanks a bunch Darien, I was always awful at percents

EDIT:
I had to rewrite the code because Darien's way would always return 0, so I rewrote it as so:

CODE

percent_done = (integer) ((time*100)/current_length);
_____________________
-Smithy
Jillian Callahan
Rotary-winged Neko Girl
Join date: 24 Jun 2004
Posts: 3,766
04-24-2008 18:54
From: Smithy Zeno
Thanks a bunch Darien, I was always awful at percents

EDIT:
I had to rewrite the code because Darien's way would always return 0, so I rewrote it as so:

CODE

percent_done = (integer) ((time*100)/current_length);
Ah, no. Darien just left out a set of parenthesys.
CODE
precent_done = (integer)((time/current_length) * 100.0);
It was doing the division then converting that to an integer then multiplying that by 100. It would return 0 until the integer conversion made it a 1, then it would return 100.