# Error: cannot convert from float to int,, when I use map()

**URL:** <https://discourse.processing.org/t/error-cannot-convert-from-float-to-int-when-i-use-map/12315>\
**Category:** Beginners\
**Created:** [June 26, 2019, 5:46pm UTC](https://discourse.processing.org/t/error-cannot-convert-from-float-to-int-when-i-use-map/12315 "2019-06-26T17:46:48Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![bu.aus](https://avatars.discourse-cdn.com/v4/letter/b/779978/32.png) [@bu.aus](https://discourse.processing.org/u/bu.aus)\
**Post date:** [June 26, 2019, 5:46pm UTC](https://discourse.processing.org/t/error-cannot-convert-from-float-to-int-when-i-use-map/12315/1 "2019-06-26T17:46:48Z")

</div>

Hello, I am a beginner and finding a problem. I wrote the following code and had error message “cannot convert from float to int”.

```auto
void serialEvent (Serial Port)
{
  brightness = float(port.readStringUntil('\n'));
  n=int(brightness);
  m=map (n,0,40,1,14);
}

```

I have already before setup function declared **m** and **n** as integer. Where is the problem? Thanks everyone.

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [June 26, 2019, 5:55pm UTC](https://discourse.processing.org/t/error-cannot-convert-from-float-to-int-when-i-use-map/12315/2 "2019-06-26T17:55:46Z")

</div>

- According to its reference: [Processing.org/reference/map\_.html](http://Processing.org/reference/map_.html)
- Function **map()** returns a `float` datatype value.
- So we need to convert it to `int` if we try to assign it to an `int` variable.
- There are many ways to do it though. Some examples:

1. `m = (int) map(n, 0, 40, 1, 14);`
2. `m = int( map(n, 0, 40, 1, 14) );`
3. `m = floor( map(n, 0, 40, 1, 14) );`
4. `m = round( map(n, 0, 40, 1, 14) );`

---

<div class="post-metadata">

**Author:** ![bu.aus](https://avatars.discourse-cdn.com/v4/letter/b/779978/32.png) [@bu.aus](https://discourse.processing.org/u/bu.aus)\
**Post date:** [June 26, 2019, 6:09pm UTC](https://discourse.processing.org/t/error-cannot-convert-from-float-to-int-when-i-use-map/12315/3 "2019-06-26T18:09:42Z")

</div>

Thank you every much:)
