Display decimals in a data set

Viewed 44

So I'm relatively new to processing and I'm trying to make a circular graph that displays precipitation over 31 days to the second decimal place. I already have the graph I want I just cant figure out how to display the decimals because its only showing 0's and 1's instead of values like 1.14, 0.04, etc. Here's the code

float [] prec = {0.19, 0.38, 0.36, 0.82, 0, 0.61, 0, 0.26, 0.06, 0.19, 0.13, 1.14, 0.05, 0, 0.07, 0, 0.03, 0, 0, 0, 0, 0, 0, 0.11, 0.04, 0.4, 0.24, 0.11, 0.04, 0.09, 0.34}; 
//daily precipitation

void setup() {
  size(900, 900);
  textAlign(CENTER);
  println(prec.length);
}

void draw() {
  background (175, 60, 150);
  translate(width/2, height/2);
  ellipse(0, 0, 50, 50);
  rotate(radians(-132));
  for (int i=0; i<prec.length; i++){ 

    rotate(radians(360/31));
    rect(0, -100, 9, -prec[i] * 200);
    text(int(prec[i]), 0, -110 - prec[i] * 225);
  }
}    
1 Answers

You cast your values as Integer in the line: text(int(prec[i]), 0, -110 - prec[i] * 225); You might want to change it for: text(prec[i], 0, -110 - prec[i] * 225);


I assume here that your can change your text() function to accept integers as the first parameter.

Related