We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Can I use text() to output a double variable? If not, what are some other ways to print it on my screen?
Thanks
// 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);
nevermind
@Devillord234 -- Note that casting to float also works, but precision differs between Double.toString(d), text(float(d),x,y), and println((float)d):
Double.toString(d)
text(float(d),x,y)
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
Answers
nevermind@Devillord234 -- Note that casting to float also works, but precision differs between
Double.toString(d)
,text(float(d),x,y)
, andprintln((float)d)
: