How do I turn a float into an integer?
#1

Just curious.
Say, I have Float:test equal to 583.19288.
I want to cut off the decimals and turn it into an integer.
How can I do it? Is there a function for this?
Reply
#2

floatround with option floatround_floor or, if you only want to display it in a string you can use %.0f specifier which will remove all the decimals and essentially displays the same as when floatround_floor is used.
Reply
#3

pawn Код:
//Make some vars
new Float:fMyFloat = 3.1;
new nMyInt;

//Cast float to int:
nMyInt = _:fMyFloat;

//nMyInt is now 3.

or

pawn Код:
//Make some vars
new Float:fMyFloat = 1.3;

//Round the float:
new nSomeInt = floatround( fMyFloat );

//nSomeInt is now 1.
https://sampwiki.blast.hk/wiki/Floats#Float_-.3E_Integer
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)