How to extract Float to Integer - 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: How to extract Float to Integer (
/showthread.php?tid=516417)
How to extract Float to Integer -
Raefal - 31.05.2014
I have value : 52.42
How to extract it to 2 Integer?
Like that:
new value[2];
value[0] = 52;
value[1] = 42;
Re: How to extract Float to Integer -
Calgon - 31.05.2014
You can use
floatround to round up a float in to an integer.
pawn Код:
new Float: fNumber = 52.42;
value[0] = floatround(fNumber, floatround_ceil);
Re: How to extract Float to Integer -
Raefal - 31.05.2014
How about value[1] ?
Quote:
Originally Posted by Calgon
You can use floatround to round up a float in to an integer.
pawn Код:
new Float: fNumber = 52.42; value[0] = floatround(fNumber, floatround_ceil);
|
Re: How to extract Float to Integer -
Calgon - 31.05.2014
It was just an example... adapt the code to what you need.
Re: How to extract Float to Integer -
KeNTos - 31.05.2014
Misunderstand you. What exactly do you want?
Quote:
new Float:value = 52.42;
new int_value = floatround(value);
|
Re: How to extract Float to Integer -
Raefal - 31.05.2014
I want to make a /givemoney [playerid] [Ammount(dollar.cent)] command, realism money system and suport for this script:
Код:
stock GivePlayerCash(playerid, dollar, cent=0)
{
new dollars, mtotal;
dollars = dollar*100;
mtotal = dollars+cent;
SetPVarInt(playerid, "Cash", GetPVarInt(playerid, "Cash")+mtotal);
GivePlayerMoney(playerid, mtotal);
return 1;
}
Sorry for my bad english
Quote:
Originally Posted by KeNTos
Misunderstand you. What exactly do you want?
|
Re: How to extract Float to Integer -
Calgon - 31.05.2014
Player money is not handled as a float, so you can't use GivePlayerMoney for that.
Take a look at
this ([Include] $$ Dollars and Cents $$), and see how they've done it.
Re: How to extract Float to Integer -
Vince - 31.05.2014
floatfract is what you need.
Re: How to extract Float to Integer -
Konstantinos - 31.05.2014
Quote:
Originally Posted by Vince
|
It's still float though and it is just 0.xxxxxx
Making the float a string and then getting the demical part with sscanf seems good way to extract them.
Re: How to extract Float to Integer -
Calgon - 31.05.2014
are you guys gonna continue to argue about which function is relevant when what he is doing is completely wrong for what he wants to make?