How to truncate Numbers and Strings?

How do you truncate an arbitrary amount of characters from a float or int? Can you do that with strings too?

I have a sketch I am using to do math on the length it takes something to wrap around a wooden dowel.

I am doing the math with floats. However, I only want the end result to display 1 digit after the decimal point. So, I'd like to trim off the last 3-5 digits. I've done this in Quartz Composer I just could not find the right path in Processing after some searching.

float D, S, C, L;

void setup()  {
  size(300, 200);
D  =  36;
S  =  0.6;
C  =  2.3;

L = ((D/S)*C)/12;

void draw()  {
  translate(width/2, height/2);
  text(L + " feet", 0, 0);


Sign In or Register to comment.