Important Things That Always Needs In Java

1. Setting limited number after decimal point in java:

double relativeSpeed =3.125878;

java.text.DecimalFormat df = new java.text.DecimalFormat();

df.setMaximumFractionDigits(2);

String r = df.format(relativeSpeed);

System.out.println(r);

 

2.  Converting string to int

String s = “123”;
int value = Integer.parseInt(s);

 

3. Converting int to string

int a = 3;
String str = Integer.toString(a);

 

 

Advertisements
  1. Leave a comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: