SA-MP Forums Archive
Problem with floatstr (inaccurate value) - 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: Problem with floatstr (inaccurate value) (/showthread.php?tid=341432)



Problem with floatstr (inaccurate value) - gangsta15 - 10.05.2012

I did not face with this problem before but, when I use floatstr it returns inaccurate value.
For example:
Код:
printf("floatstr -1772.8328 result is: %f", floatstr("-1772.8328"));
printf("floatstr 1555.17 result is: %f", floatstr("1555.17"));
Quote:

floatstr -1772.8328 result is: -1772.832763
floatstr 1555.17 result is: 1555.170043

How to solve this problem? (If the full code needed - tell me)

Using 0.3e server, coding a filterscript.
Includes: mysql, zcmd, cstl
Plugins: mysql, cstl



Re: Problem with floatstr (inaccurate value) - Yuryfury - 11.05.2012

You can try this (haven't tested):
pawn Код:
printf("floatstr -1772.8328 result is: %.4f", floatstr("-1772.8328"));
printf("floatstr 1555.17 result is: %.2f", floatstr("1555.17"));
This makes the float only have 4 and 2 decimal places (respectively)


Re: Problem with floatstr (inaccurate value) - gangsta15 - 11.05.2012

Quote:
Originally Posted by Yuryfury
Посмотреть сообщение
You can try this (haven't tested):
pawn Код:
printf("floatstr -1772.8328 result is: %.4f", floatstr("-1772.8328"));
printf("floatstr 1555.17 result is: %.2f", floatstr("1555.17"));
This makes the float only have 4 and 2 decimal places (respectively)
There is a big number of floats in my filterscript, and it is not the solution, but anyway - thanks.