To avoid having to declare a variable, is it possible to convert a double variable to a string within a CanvasText?
double cxg = 74.35;
canvas.drawText(cxg, 250, 10, paint);
This gives me an error since cxg is double.
To avoid having to declare a variable, is it possible to convert a double variable to a string within a CanvasText?
double cxg = 74.35;
canvas.drawText(cxg, 250, 10, paint);
This gives me an error since cxg is double.
Assuming that you are programming in Java, you can use the function String.valueOf
to convert from double
to String
:
double cxg = 74.35;
canvas.drawText(String.valueOf(cxg), 250, 10, paint);
I hope it serves you. Greetings!
The method drawText certainly needs a String
to define the text that will be displayed:
drawText (String text,
float x,
float y,
Paint paint)
in this you must convert the value double
to String
, you can do it using these options:
Concatenating a String
(empty):
canvas.drawText(""+cxg, 250, 10, paint);
Using the method String.valueOf () :
canvas.drawText(String.valueOf(cxg), 250, 10, paint);
Using the method toString () the variable with value type double
:
canvas.drawText(cxg.toString(), 250, 10, paint);