Glitch or? - 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: Glitch or? (
/showthread.php?tid=610763)
Glitch or? -
TwinkiDaBoss - 28.06.2016
Alright I attempted something but theres a problem.
PHP код:
#define PRICE 0.70
printf("%.2f",PRICE);
it will output as 0.69. Only happens with 0.70
Re: Glitch or? -
Vince - 28.06.2016
Slightly odd, but not totally unexpected given the way floating point arithmetic works. They aren't very precise but good enough for most purposes. The number might as well have been stored as 0.699999... but because you cut it off at two characters it displays that.
https://www.youtube.com/watch?v=PZRI1IfStY0
Re: Glitch or? -
Stinged - 28.06.2016
You could show the number as 2 integers separated by a point.
Код:
new
Float: price = 0.70,
before = floatround(price, floatround_tozero),
after = floatround(price * 100) - before * 100;
printf("%i.%i", before, after);
Multiple it by 10^x with x being how many numbers there are after the decimal point.
Re: Glitch or? -
Luicy. - 28.06.2016
PHP код:
#define PRICE 0.70
if(floatcmp(0.70, PRICE) == 0)
printf("0.70");
else
printf("%f",PRICE);