Computer Science, asked by ashamishra170pci228, 1 year ago

how to type two decimal places in java? ex- INPUT - 12.367 OUTPUT - 12.37 WITHOUT USING MATH CLASS

Answers

Answered by nitish8089
4
you could use
___________________________________
public class program{
double x=12.367;
String str=String.format("%.2f", x);
System.out.println(str);
}
Attachments:

ashamishra170pci228: thank thank thank thank thank thank thank thank you sooooooooooo much
nitish8089: welcome
ashamishra170pci228: any other logic other than this math class
nitish8089: it's String class.
ashamishra170pci228: i know other than string class also if there plz send or it is enough
nitish8089: format method but by logic i will try...
ashamishra170pci228: sure thanks
ashamishra170pci228: hope you for the best
Similar questions