Float 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: Float value (
/showthread.php?tid=322821)
Float value -
nuriel8833 - 03.03.2012
I have a question
If I have a float (lets say for ex: 27.000),and I want to print only the 27 part? how can I do so?
for ex if I use %.2f that will print 27.00,and %.1f will print 27.0
I want it to print only 27.
How can I do it?
Thanks 4 helpers
nuriel
Re: Float value -
Konstantinos - 03.03.2012
Re: Float value -
aco_SRBIJA - 03.03.2012
I hope this function is avalilable in C++ since it is everywhere.
new Float

= 27000
while (x mod 10 = 0)
{
x=x div 10;
}
What it does? it does a loop with the condition if x is divided by 10, it should be integer as a result. If yes, divide by ten. And it goes.
1 check:
27 000 mod 10 = 0 //accuried
27 000 div 10 = 2700
2) 2700 mod 10 = 0
2700 div 10 = 270
3) 270 mod 10 = 0
270 div 10 = 27
4) 27 mod 0 != 0, there it's breaking, so x = 27.
Yeah, script's looks strange, but you can do with whatever number/float this which you want to convert in that way.