Archive for category Java

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

Leave a comment