Arduino - Cast

Arduino

Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ

Blog » | Forum » | Playground »

Reference Language (extended) | Libraries | Comparison | Board

## Cast

#### Description

The cast operator translates one variable type into another and forces calculations to be performed in the cast type.

#### Syntax

(type)variable

#### Parameters:

type: any variable type (e.g. int, float, byte)

variable: any variable or constant

#### Example

    int i;
    float f;

    f = 3.6;
    i = (int) f; // now i is 3

#### Note

When casting from a float to an int, the value is truncated not rounded. So both `(int) 3.2` and `(int) 3.7` are 3.

Reference Home

Corrections, suggestions, and new documentation should be posted to the Forum.

The text of the Arduino reference is licensed under a Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain.

Edit Page | Page History | Printable View | All Recent Site Changes