How to use text() for double

edited May 2017 in How To...

Can I use text() to output a double variable? If not, what are some other ways to print it on my screen?

Thanks

Tagged:

Answers

  • edited May 2017
    // forum.Processing.org/two/discussion/22845/how-to-use-text-for-double#Item_1
    // GoToLoop (2017-May-31)
    
    size(600, 150);
    smooth(3);
    noLoop();
    
    fill(#FFFF00);
    background(#0000FF);
    
    textSize(050);
    textAlign(CENTER, BASELINE);
    
    double d = -Math.E;
    text(Double.toString(d), width>>1, height>>1);
    //text("" + d, width>>1, height>>1);
    
  • edited May 2017

    nevermind

  • edited May 2017

    @Devillord234 -- Note that casting to float also works, but precision differs between Double.toString(d), text(float(d),x,y), and println((float)d):

    size(200, 150);
    double d = Math.E;
    text(Double.toString(d), 10, 20); // 2.718281828459045
    println(Double.toString(d));      // 2.718281828459045
    text((float)d, 10, 40);           // 2.718
    println((float)d);                // 2.7182817
    
Sign In or Register to comment.