- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Convert variables from one type to another in Arduino
In order to convert variables from one type to another, you use the CAST operator. The syntax is −
(type) var;
Where var is the variable to be casted, and type is the new type to which you wish to convert it. For example, if you have a variable of type float, and wish to cast it as an int.
Example
Here’s how you can do it −
float f; int i; void setup() { // put your setup code here, to run once: f = 5.6; i = (int) f; Serial.println(f); Serial.println(i); } void loop() { // put your main code here, to run repeatedly: }
The Serial Monitor will print 5.6 followed by 5 (and not 6). This is because casting a float to int truncates the float, doesn’t round it.
- Related Articles
- Golang Program to convert double type variables to int
- Golang Program to convert double type variables to string
- Golang Program to convert int type variables to String
- Swift Program to Convert Char type variables to Int
- Swift program to convert double type variables to int
- C++ Program to Convert long Type Variables to int
- C++ Program to Convert int Type Variables to long
- Golang Program to convert long type variables to int
- Golang Program to convert int type variables to long
- Haskell Program to convert int type variables to long
- Haskell Program to convert int type variables to char
- Golang Program to convert string type variables into Boolean
- Golang Program to convert string type variables into int
- C++ Program to Convert String Type Variables into Boolean
- C++ Program to Convert int Type Variables into String

Advertisements