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

  • According to its reference: 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) );
2 Likes