how to type two decimal places in java? ex- INPUT - 12.367 OUTPUT - 12.37 WITHOUT USING MATH CLASS
Answers
Answered by
10
Method - 1:
import java.util.*;
class Demo
{
public static void main(String[] args)
{
double d = 12.367;
System.out.printf("%.2f", d);
}
}
-----------------------------------------------------------------------------------------------------------------
Method - 2:
import java.text.*;
class Demo
{
public static void main(String[] args)
{
double d = 12.367;
DecimalFormat hello = new DecimalFormat("#.##");
System.out.println(hello.format(d));
}
}
----------------------------------------------------------------------------------------------------------------
Output: 12.37.
Hope this helps!
ashamishra170pci228:
thank you
Similar questions
Math,
6 months ago
India Languages,
6 months ago
Math,
6 months ago
Social Sciences,
1 year ago
Social Sciences,
1 year ago
Math,
1 year ago
Geography,
1 year ago