How can I convert int, float and other numbers to String type? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How can I convert int, float and other numbers to String type?

when i try to act stupid and be like string x; int y = 67; x = (string) 67; it throws an error in me

29th Dec 2017, 8:16 PM
hide on bush
hide on bush - avatar
3 Answers
+ 6
or just use String.valueOf(variable)
29th Dec 2017, 8:46 PM
romangraef
+ 4
public class Program { public static void main(String[] args) { Integer x = 2016; Float f = 2017.12; Double d = 2018.01; System.out.println(x.toString()); System.out.println(d.toString()); System.out.println(f.toString()); } } (Edit) Cant use primitive types for that : ) Hth, cmiiw
29th Dec 2017, 8:44 PM
Ipang
+ 2
Actually, @romangraef has the answer, it's the flexible way to do it : )
30th Dec 2017, 2:23 AM
Ipang