Link to home
Start Free TrialLog in
Avatar of gudii9
gudii9Flag for United States of America

asked on

double exponentioal notation

hi, i am trying below pogram
public class test {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
exByte();
	}
	
	public static void exByte(){
		double d=3.4444d;
		d=34444-04;//exponential notation
		System.out.println("d is"+d);
	}

}

Open in new window


i got out put
d is34440.0


can i represent positive exponential as below?
d=34444+04;//exponential notation

please advise
Avatar of gudii9
gudii9
Flag of United States of America image

ASKER

public class test {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
exByte();
	}
	
	public static void exByte(){
		float f=3.4444f;
		double d=3.4444d;
		d=34444-04;//exponential notation
		System.out.println("d is"+d);
		System.out.println("d==f is"+ d==f);
	}

}

Open in new window


why above gives compile error.

below why giving false.

public class test {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
exByte();
	}
	
	public static void exByte(){
		float f=3.4444f;
		double d=3.4444d;
		d=34444-04;//exponential notation
		System.out.println("d is"+d);
		System.out.println(d==f);
	}

}

Open in new window

Avatar of ozo
34444e+04 is 3.4444E8
double d=3.4444d;
float f=3.4444f;
d=34444-04;//subtraction notation
System.out.println("d is"+d);
System.out.println("f is"+f);
System.out.println("d==f is"+ (d==f));
d=34444e-04;//exponential notation
System.out.format("d is %.16f\n",d);
System.out.format("f is %.16f\n",f);
System.out.println("d==f is"+ (d==f));

                                 
d is34440.0
f is3.4444
d==f isfalse
d is 3.4444000000000000
f is 3.4444000720977783
d==f isfalse
d is34440.0
d is3.4444E8
Avatar of gudii9

ASKER

public class test4 {

      /**
       * @param args
       */
      public static void main(String[] args) {
            // TODO Auto-generated method stub
exByte();
      }
      
      public static void exByte(){
            float f=3.4444f;
            double d=3.4444d;
            d=34444-04;//exponential notation
            System.out.println("d is"+d);
               System.out.println("d==f is"+ d==f);
            System.out.println("d==f is"+ f==d);

      }

}

both of above bolded lines giving error incomatible types even high precision double assigned to low precision float or vice versa.

please advise
+ has precedence over ==, so "d==f is"+ d==f means ("d==f is"+ d)==f
Those lines should have been
               System.out.println("d==f is"+ (d==f));
            System.out.println("d==f is"+ (f==d));
Avatar of gudii9

ASKER

d=34444-04;//subtraction notation

what it mean by subtraction notation
why it gave output
d is34440.0
Subtracting four from thirty-four thousand four hundred forty-four leaves thirty-four thousand four hundred forty
Avatar of gudii9

ASKER

oh
Avatar of gudii9

ASKER

public class testing {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		double d=3.4444d;
		double d1=3.4444d;
		float f=3.4444f;
		d=34444-04;//subtraction notation
		d1=34444+04;
		System.out.println("d is"+d);
		System.out.println("d1 is"+d1);
		System.out.println("f is"+f);
		System.out.println("d==f is"+ (d==f));
		d=34444e-04;//exponential notation
		System.out.format("d is %.16f\n",d);
		System.out.format("f is %.16f\n",f);
		System.out.println("d==f is"+ (d==f));

	}

}

Open in new window


above gives
d is34440.0
d1 is34448.0
f is3.4444
d==f isfalse
d is 3.4444000000000000
f is 3.4444000720977783
d==f isfalse

Open in new window


how it exponential operator different from addition or subtraction. please advise
Avatar of gudii9

ASKER

what it mean by "double exponentioal notation"
Avatar of gudii9

ASKER

public class testing {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		double d = 3.4444d;
		double d1 = 3.4444d;
		float f = 3.4444f;
		d = 34444 - 04;//subtraction notation
		d1 = 34444 + 04;
		System.out.println("d is" + d);
		System.out.println("d1 is" + d1);
		System.out.println("f is" + f);
		System.out.println("d==f is" + (d == f));
		double d3 = 34444e-04;//exponential notation
		//float f3 = 34444e-04;//exponential notation
		System.out.format("d3 is %.16f\n", d3);
		//System.out.format("f is %.16f\n", f3);
		System.out.println("d==f is" + (d == f));

	}

}

Open in new window



i got output as
d is34440.0
d1 is34448.0
f is3.4444
d==f isfalse
d3 is 3.4444000000000000
d==f isfalse

Open in new window

Avatar of gudii9

ASKER

double d3 = 34444e-04;//exponential notation

means like below right
d3=34444*(10 to the power of -4)

which is moving the decimal to left side 4 digits as below
d3 is 3.4444000000000000


i wonder why below line giving compilation error

//float f3 = 34444e-04;//exponential notation

please advise
ASKER CERTIFIED SOLUTION
Avatar of ozo
ozo
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial