floatround problem - 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: floatround problem (
/showthread.php?tid=517361)
floatround problem -
polander - 04.06.2014
When i try this:
PHP код:
new a = 500;
new b = 10;
new c = floatround( b/100*a );
printf("Result: %d", c);
I get 'c' = 0, but the correct answer is 50. Wtf? Why?
Re: floatround problem -
Rittik - 04.06.2014
pawn Код:
floatround(c, floatround_ceil);
Re: floatround problem -
polander - 04.06.2014
PHP код:
new a = 498;
new b = 7;
new Float:d = b/100*a; // it's 34,86
new c = floatround( d ); // it's 35
printf("Result: %d", c);
What's wrong?
Re: floatround problem -
Vince - 04.06.2014
The right part gets executed first and then the result is written to the part on the left. Define your operands as a float with the appropriate tag, or use float(), or use any of the float functions (floatmul, floatdiv). It might also simply work like this, although I'm not entirely sure;
The '.0' is important. Actually that should be done at all times when working with floating point values in Pawn. Even in functions like SetPlayerHealth, etc.
Re: floatround problem -
polander - 04.06.2014
But really in pawn not observed mathematical action order?

Anyway thanks, i try this 'b/100.0*a' and it works.
Re: floatround problem -
polander - 05.06.2014
I didnt't ignore your post, i just didn't consider it helpful, because given expression IS a float, but you wrote that it isn't..
Re: floatround problem -
Rittik - 05.06.2014
Код:
new Float:a = 500.0;
new Float:b = 10.0;
new Float:d=b/100*a
new c = floatround(d, floatround_ceil);
printf("Result: %d", c);
Re: floatround problem -
polander - 05.06.2014
******, i respect you and your jobs, but really, this answer wasn't enough informative for me. "Neither of your inputs are floats", and what? Why they arent'a floats? What should i do with this? Your knowledge is your knowledge and i can't read your mind, so i asked this topic question
Re: floatround problem -
polander - 05.06.2014
Rittik, thank you, i already understood