Java Program to remove the trailing zeroes from the long digit :
Trailing zeroes can be removed from the long digit by using the DecimalFormat class. Below is one such example.
import java.text.DecimalFormat;
public class removeTrailingZero {
public static void main(String[] args) {
double answer = 5.0;
double answer1 = 4.50;
double answer2 = 5.25;
DecimalFormat df = new DecimalFormat("###.##");
System.out.println(df.format(answer));
System.out.println(df.format(answer1));
System.out.println(df.format(answer2));
String x = df.format(answer);
System.out.println(x);
}
}
Trailing zeroes can be removed from the long digit by using the DecimalFormat class. Below is one such example.
import java.text.DecimalFormat;
public class removeTrailingZero {
public static void main(String[] args) {
double answer = 5.0;
double answer1 = 4.50;
double answer2 = 5.25;
DecimalFormat df = new DecimalFormat("###.##");
System.out.println(df.format(answer));
System.out.println(df.format(answer1));
System.out.println(df.format(answer2));
String x = df.format(answer);
System.out.println(x);
}
}
No comments:
Post a Comment