Just practice
#1

Hey I was wondering how to display something in percents so this is what I did:

pawn Код:
new Celota = 270;
new Enota = 270;
pawn Код:
SetTimerEx("EnotaDol", 1000, true, "i", playerid);
pawn Код:
public EnotaDol()
{
    Enota --;
    return 1;
}
pawn Код:
stock Procenti(playerid)
{
    new string[128];
    new Procent;
    Procent = floatround((Enota / Celota)*100, floatround_round);
   
    format(string, sizeof(string),"There is currently %d Enot, which is exactly %.0f% percent!",Enota,float(Procent));
    SendClientMessage(playerid,-1,string);
}
pawn Код:
CMD:procenti(playerid, params[])
{
    Procenti(playerid);
    return 1;
}
Everything is working fine but.. it doesn't actually calculate how much percent is "Enota" of 270...(Celota) so it says "which is exactly 0 percent" .. can you help me out from this cuz I somehow feel I'm so close with that code..
Reply
#2

Floataround returns as int and you are trying to display it as float.

pawn Код:
new Float:CurrentPercent = (Enota/Celota)*100
printf("%f%%",CurrentPercent);
example
pawn Код:
(220/250)*100 = 88.00%
Which means, Enota is 12% less than Celota
Reply
#3

Not working properly first time it shows 100% but other numbers are displayed still as 0..
So what I'm trying to do is to reduce 270 for 1 every 1 second and display this in percentage everytime..
Added your code but not working properly

pawn Код:
stock Procenti(playerid)
{
    new string[128];
    new Float:CurrentPercent = (Enota/Celota)*100;
    printf("%f%%",CurrentPercent);

    format(string, sizeof(string),"There is currently %d Enot, which is exactly %.0f% percent!",Enota,CurrentPercent);
    SendClientMessage(playerid,-1,string);
}
Bit more help ? ^^
Reply
#4

Quote:
Originally Posted by Razturach
Посмотреть сообщение
Not working properly first time it shows 100% but other numbers are displayed still as 0..
So what I'm trying to do is to reduce 270 for 1 every 1 second and display this in percentage everytime..
Added your code but not working properly

pawn Код:
stock Procenti(playerid)
{
    new string[128];
    new Float:CurrentPercent = (Enota/Celota)*100;
    printf("%f%%",CurrentPercent);

    format(string, sizeof(string),"There is currently %d Enot, which is exactly %.0f% percent!",Enota,CurrentPercent);
    SendClientMessage(playerid,-1,string);
}
Bit more help ? ^^
Try changing
pawn Код:
(Enota/Celota)*100;
to
pawn Код:
((Enota/Celota) *100);

Look at this thread
http://forum.sa-mp.com/archive/index.php/t-114524.html
Reply
#5

Make sure EVERYTHING has the tag Float so the correct operator is used... or just use floatdiv or floatmul.

So, First of all, Set the Enota and Celota correctly by doing:
PHP код:
new Float:Celota 270.0;
new 
Float:Enota 270.0
And then at the stock:
PHP код:
stock Procenti(playerid)
{
    new 
string[128];
    new 
Procent floatround(((Enota Celota) * 100.0), floatround_round);
    
    
format(stringsizeof(string),"There is currently %f Enot, which is exactly %.0f% percent!",Enota,float(Procent));
    
SendClientMessage(playerid,-1,string);

Try it and tell us if it works.
Reply
#6

new Float:CurrentPercent = (Enota*100.0/Celota);
Reply
#7

Without your help I wouldn't figure it out guys so the final code is:
pawn Код:
stock Procenti(playerid)
{
    new string[128];
    new Float:CurrentPercent = floatround ((100 * Enota) / Celota);
    printf("%f%%",CurrentPercent);

    format(string, sizeof(string),"There is currently %d Enot, which is exactly %.0f% percent!",Enota, CurrentPercent);
    SendClientMessage(playerid,-1,string);
}
And it's exactly what I wanted ^^
Ty
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)