SA-MP Forums Archive
[Ajuda] Float / Int - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: Non-English (https://sampforum.blast.hk/forumdisplay.php?fid=9)
+--- Forum: Languages (https://sampforum.blast.hk/forumdisplay.php?fid=33)
+---- Forum: Português/Portuguese (https://sampforum.blast.hk/forumdisplay.php?fid=34)
+---- Thread: [Ajuda] Float / Int (/showthread.php?tid=475188)



Float / Int - Zivo - 11.11.2013

Como armazenar uma variбvel inteira numa float?
Tipo assim:

pawn Код:
format(String, sizeof(String), "%s", tmp);
        nr1 = floatstr(String);
        format(String, sizeof(String), "%s", tmp3);
        nr2=floatstr(String);
Sу que de um jeito mais correto


Re: Float / Int - WLSF - 11.11.2013

pawn Код:
new Float: x, y = 10;

x = y;
basta atribuir o valor do inteiro na float...


Re: Float / Int - Kimossab - 11.11.2013

Para que й que tu estбs a usar strings se o que queres й inteiros e floats?

Passar de um float para um inteiro acho que nгo tгo fбcil mas de inteiro para float й sу fazer como o willian disse. Boa sorte com isso.


Re: Float / Int - WLSF - 11.11.2013

Quote:
Originally Posted by Kimossab
Посмотреть сообщение
Passar de um float para um inteiro acho que nгo tгo fбcil.
pawn Код:
new Float:x, y;

x = 2.0;

y = floatround(x);



Re: Float / Int - Kimossab - 11.11.2013

Quote:
Originally Posted by Willian_Luigi
Посмотреть сообщение
pawn Код:
new Float:x, y;

x = 2.0;

y = floatround(x);
Uhm, pois nao me lembrei dessa funзгo, estava a pensar em C, aн acho que nao existe uma funзгo igual ou parecida, mas pronto, tб-se sempre a aprender xD


Re: Float / Int - WLSF - 11.11.2013

Quote:
Originally Posted by Kimossab
Посмотреть сообщение
Uhm, pois nao me lembrei dessa funзгo, estava a pensar em C, aн acho que nao existe uma funзгo igual ou parecida, mas pronto, tб-se sempre a aprender xD
Acho que um typecast em C jб basta...

Код:
int x;
float y = 20.0;

x = (int)(y+0.5);



Re: Float / Int - Kimossab - 11.11.2013

Quote:
Originally Posted by Willian_Luigi
Посмотреть сообщение
Acho que um typecast em C jб basta...

Код:
int x;
float y = 20.0;

x = (int)(y+0.5);
Bem dessa eu nгo sabia, mas tambйm ainda sу comecei este mes a aprender C :P

Obrigado. Mas jб tamos a ir um pouco off topic xD


Re: Float / Int - WLSF - 11.11.2013

O assunto ainda sim estб em cast/conversгo de tipos.

Й bom isto, que poupamos a criaзгo de tуpicos novos.



Abraзos.