Multiplying doubles in java?

I'm trying to multiply the same double (square it) but the number comes out wrong. When i display the double by itself the number is correct but when i multiply it by itself it comes up with the wrong number. I already tried using the math.pow function and got the same result.

    Double height=Double.parseDouble(myPrefs.getString("Heightent",""))*.0254;
    Double bmi = (height*height);
    dbmi.setText(bmi.toString());

Height is entered in a different activity in inches. When i display height in a text box it comes out to be the right number. For example, Heightent entered is 74 and 1.8796 is displayed when i put height in a textview. Butwhen I use the code above the number 16 is displayed in TextView dbmi. Any help?

Answers


Check out this great post by Stephen C.

https://stackoverflow.com/a/5385202/1214163

It should provide everything you need. He suggests that if you need to work with big numbers that you use the BigDecimal class


I tried both

    Double height=Double.parseDouble("74")*.0254;
    Double bmi = (height*height);
    System.out.println("first " + bmi);


      height=Double.parseDouble("74");
      double temp = height.doubleValue()*.0254;
      bmi = (temp*temp);
      System.out.println("Second " + bmi);

and on Calc

and got same every where.....


Need Your Help

How can I change the size of a Bootstrap checkbox?

css twitter-bootstrap checkbox laravel-4 laravel-blade

Wondering if its possible to change the size of checkbox as it's possible with buttons. I want it to be bigger, so it makes it easy to press. Right now its looking like this:

PHP Display Alternating Records from Table

php mysql foreach

Ok, so, you guys were extremely helpful with my last issue, so , why not try again?