SA-MP Forums Archive
---> Need help with Float. - 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: ---> Need help with Float. (/showthread.php?tid=440393)



---> Need help with Float. - sKgaL - 29.05.2013

Hey,
Lets say I have this float:
Код:
65.6895282826
And I want to turn this float into:
Код:
65.68
... How can I do this?


Thanks.


Re: ---> Need help with Float. - Pottus - 29.05.2013

What what I understand there might be a better way to do this but if you trying to save to a file do this.

new line[128];
format(line, sizeof(line), "%0.2f %0.2f %0.2f %0.2f", float1, float2, float3, float4);

That will round out to 2 decimal places.

Now if your not saving and want to round it try this

new roundvalue[32];

format(roundvalue, sizeof(roundvalue), "0.2f", floatvalue);
floatvalue = floatstr(roundvalue);

Mind you floats are not accurate so it probably won't round as expected.


Re: ---> Need help with Float. - sKgaL - 29.05.2013

Awsome,works great.
Thanks.