How to extract Float to Integer
#1

I have value : 52.42
How to extract it to 2 Integer?
Like that:
new value[2];
value[0] = 52;
value[1] = 42;
Reply
#2

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);
Reply
#3

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);
Reply
#4

It was just an example... adapt the code to what you need.
Reply
#5

Misunderstand you. What exactly do you want?

Quote:

new Float:value = 52.42;
new int_value = floatround(value);

Reply
#6

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?
Reply
#7

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.
Reply
#8

floatfract is what you need.
Reply
#9

Quote:
Originally Posted by Vince
Посмотреть сообщение
floatfract is what you need.
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.
Reply
#10

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?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)