Diferencia entre revisiones de «float()»

De ArduWiki
Saltar a: navegación, buscar
(Advertencias)
(Ejemplo)
 
(No se muestran 4 ediciones intermedias del mismo usuario)
Línea 4: Línea 4:
 
== Sintaxis ==
 
== Sintaxis ==
 
<pre>
 
<pre>
float(variale);
+
float(variable);
 
</pre>
 
</pre>
  
 
== Parametros ==
 
== Parametros ==
;variable: variable de cualquier tipo a evaluar.
+
;variable: variable de cualquier tipo a evaluar. [[char]], [[byte]], [[int]], [[long]], [[double]].
  
 
== Retorna ==
 
== Retorna ==
Línea 20: Línea 20:
 
char a = 'A';
 
char a = 'A';
 
byte b = 123;
 
byte b = 123;
int c = -123.45;
+
int c = -12345;
  
 
void setup(){
 
void setup(){
Línea 47: Línea 47:
  
 
== Vea también ==
 
== Vea también ==
* [[char()]]
+
<categorytree mode=all>Funciones conversion</categorytree>
* [[byte()]]
 
* [[int()]]
 
* [[word()]]
 
* [[long()]]
 
  
== Referencias ==
+
== Referencias externas ==
 
* [https://www.arduino.cc/reference/en/language/variables/data-types/float/ Guia de referencia de Arduino]
 
* [https://www.arduino.cc/reference/en/language/variables/data-types/float/ Guia de referencia de Arduino]
 
* [http://rufianenlared.com/float/ Float, eres problematico y Arduino lo sabe] - Rufian de la Red
 
* [http://rufianenlared.com/float/ Float, eres problematico y Arduino lo sabe] - Rufian de la Red
  
[[Category:Funciones]]
+
[[Category:Funciones conversion]]

Revisión actual del 20:46 18 jul 2019

Descripción

Convierte un valor numérico de cualquier tipo a float.

Sintaxis

float(variable);

Parametros

variable
variable de cualquier tipo a evaluar. char, byte, int, long, double.

Retorna

Retorna un numero tipo float.

Advertencias

No funciona con cadenas string ni objetos String.

Ejemplo

char a = 'A';
byte b = 123;
int c = -12345;

void setup(){
   Serial.begin(9600);

   byte valor1 = byte(a);
   Serial.println(valor1);

   int valor2 = long(b);
   Serial.println(valor2);

   unsigned int valor3 = word(b);
   Serial.println(valor3);

   long valor4 = long(b);
   Serial.println(valor4); 

   float valor5 = float(c);
   Serial.println(valor5); 
}
 
void loop(){
   //Nada.
}

Vea también


Referencias externas