SA-MP Forums Archive
Number - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Number (/showthread.php?tid=640659)



Number - Chipardeur - 05.09.2017

Код:
new Float:number;
number = -0.57;

if(number < 0)
{
    number = -number;
    printf("%d", number);
}
Why i have this 1058139013?

I search to transform -0.57 to 0.57


Re: Number - aoky - 05.09.2017

PHP код:
if(number 0)
{
    
number = -number;
    
printf("%f"number);

PHP код:
 %integer 
PHP код:
 %float 



Re: Number - Chipardeur - 05.09.2017

oh yes i'm stupid looool


Re: Number - aoky - 05.09.2017

Mistakes are made, glad I helped.


Re: Number - Eoussama - 05.09.2017

When calculating float numbers, use
floatadd instead of +
floatsub instead of -
floatmul instead of *
floatdiv insrtead of /

More on Floats


Re: Number - Misiur - 05.09.2017

What? No reason for that. See "float.inc" in your pawno include folder - and look at all functions containing "operator" in name - those are operator overloads


Re: Number - Paulice - 05.09.2017

If you only need it once you can do, for example (removing the need of "number = -number;"):
PHP код:
printf("%f", -number); 
You could also do
PHP код:
number *= -1
instead of "number = -number;".


Re: Number - Storm94 - 05.09.2017

Why are you trying to reinvent the wheel?

Код:
floatabs(Float: value);