Go Down

Topic: Converting float to int (Read 5725 times) previous topic - next topic

mrdovey

Ok. Try this:

Code: [Select]
float x = 55.6;
int a;

void setup(){
 
}
void draw(){
 
  background(0);
  fill(255);
  x = round(x);
  a = (int)x;
  a = 100 * a / 60;
  rect(0,0,a,50);
}

Theelectronicguy

#16
Jan 26, 2012, 02:41 am Last Edit: Jan 26, 2012, 02:49 am by Theelectronicguy Reason: 1
Tried it, it works but not sure how it helps?
I also added a println of a and the value returned is 93 which seems about right. So it must be the map function that doesnt work?


mrdovey

Dunno. I made /two/ changes: (1) I re-wrote your cast so that it couldn't be confused with a function call and (2) did the mapping the "hard" way.

Theelectronicguy

#18
Jan 26, 2012, 02:51 am Last Edit: Jan 26, 2012, 03:03 am by Theelectronicguy Reason: 1
LOL I should start reading the processing referance:http://processing.org/reference/map_.html

I assumed the map function worked for integers but its the opposite(it works for float).However it was the compiler that told me the wrong thing :).

Thanks a lot for the help :D.

Go Up