Wednesday, December 6, 2017

JAVA - How convent number to string

int to String

int i = 10;
String s = Integer.toString( i );

System.out.println( s );  // write result to Output window
Output:
10

long to String

long l = 456;
s = Long.toString( l );

System.out.println( s );  // write result to Output window
Output:
456

double to String

double d = 5.51;
s = Double.toString( d );

System.out.println( s );  // write result to Output window
Output:
5.51

float to String

float f = 15.55f;
s = Float.toString( f );

System.out.println( s );  // write result to Output window
The output is:
15.55

No comments:

Post a Comment