ATM : Getting wa

import static java.lang.Math.abs;
import java.util.Scanner;
class Sample1 {
public static void main(String[] args){
Scanner scan = new Scanner(;
double per = scan.nextDouble();
float s =0.50f;
double a=120.00,b;
b = abs(per-120.00);



can anyone help me? actuall im not getting answer as 89.50, but im getting only 89.5??? why?? im banging my head

Put your code in proper blocks, no offense but it is even tough to read. You may post ideone link also. :slight_smile:

Convert the number to string and try formatting the string using the below code. (".2f" is for 2 decimal places) String st = String.valueOf(a); String str=String.format(".2f",st);

Refer this.