Double to float

I found in APIs, there is a method: floatValue() to transfer double to float.But when I wrote the following code and compiled it, the error is:
myjava.java:437: double cannot be dereferenced
float ba=aa.floatValue();
program:
double aa=4;
float ba=aa.floatValue();
What's the problem in my program?
Thanks

That does not work because the floatValue() method exists in the Double wrapper class and not for the double primitive type. You should try either:
double aa = 4;
Double d = new Double(aa);
float ba = d.floatValue();or
double aa = 4;
float ba = (float)aa;

Similar Messages

  • Convert double precision float string to a number

    I am a newbie with Labview.
    I have a GPIB link with a vector voltmeter and I receive the data as a double precision float string (IEEE standard 754-1985). I would like it to be recognized as a number, but I can't find the proper conversion function. The string to convert is 8 byte long. Does anyone have an idea how to do it? Thank you!

    Asumming your data is big-endian, you should be able to simply typecast it to a DBL (see attache LV 7.0 example).
    (It is possible that your DBL string is little-endian, in this case it will be slightly more complicated. Let us know )Message Edited by altenbach on 05-27-2005 04:49 PM
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    StringToDBL.vi ‏23 KB

  • Casting arrays from double to float

    Hi, wonder if anyone can help.
    I have a method of a class that creates two double arrays (the value pointed to is a double type)
    x[][]
    y[][]
    they are essentially co-ordinates. The first dimension of the array holds the polygon number, the second the point on that polygon for the x and y respectivly.
    This method is called from (and therefore the arrays returned to) a class in an applet i am designing.
    I now have to get these co-ords into a general path for display. A general path only takes float values. I have tried all the normal casting tricks to try to convert these doubles into floats and nothing is working. Do you have to do anything special because they are in arrays.
    Any help would be appriciated.

    There is nothing special about array except that you cannot cast them.
    Instead you need to create a new set of arrays and copy/cast each value individually.

  • How to convert a String data to Double or Float???? Thank you

    I need to convert String data to Double or Float , please help me about it. Thank you very muh!
    String a=Integer.parseInt("1234"); convert to integer.

    I found it but do not know if it is ok
    float a= Float.valueof(String to
    convert).floatValue();
    may be it can be!!!
    Thank you !!!!How did parseInt lead you do valueOf?
    Look for something more consistent. A pattern.As I said earlier, it depends if he wants an object or a primitive.
    � {�                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Help with double and float

    I added the (float) after the = in both and it fixed the top and not the bottom. "cant convert double to float" (as well as the answer to this, if somone could correct my terminology as well it would be appretiated. thanks in advance)
    float torontoF = (float)(torontoC * 1.8) + 32;
         System.out.print (torontoF);
    x      float stockholmC = (float)(stockholmF ? 32)* .5556;
         System.out.print (stockholmF);

    Reposted and answered at:
    http://forum.java.sun.com/thread.jspa?threadID=5219089
    Do not reply here.

  • Cannot explicit convert double.MaxValue/double.MinValue/float.MaxValue/float.MinValue to decimal

    I'm try set double.MaxValue/double.MinValue/float.MaxValue/float.MinValue to NumericUpDown's Maximun/Minimum
    It fail (compile error)
    but variable and constant's explicit conversion is OK.
    can anyone tell me why?
    the screenshot is in below
    http://i.imgur.com/woZXr0i.png

    yes, your right!
    I has been tried
    If I assign it(MinValue/MaxValue) to a variable first and then explicit convert to a decimal
    it will be pass compile, but it will throw exception when runtime
    screenshot
    http://i.imgur.com/TpD8guJ.png

  • Converting double to float

    This problem only occurs when dealing with large numbers or numbers with a lot of fraction digits.
    Here is an example:
    double d = 7.1E9;
    float f1 = (float)d;
    float f2 = new Float(d).floatValue();
    System.out.println( d + " " + f1 + " " + f2);
    The result is:
    7.1E9 7.1000003E9 7.1000003E9
    I tried other ways of converting to float (using DecimalFormat) but unfortunately nothing works. The resulting float is not the same as the original double.
    Any ideas?
    Thanks.
    Igor.

    float is only 32 bit while double is 64 bit, so you can easily get differences like that.
    Is it a problem? If you results gets inaccurate you should stay with double or use BigDecimal if you really care about the precision. If it's because you want to round the result of before you display it, you can use DecimalFormat.

  • Viewing only x number of digits for double or float

    I was wondering if I had a float or a double, and lets say I didn't want to see all those decimal places, is there a way for me to limit the number of decimal places that is outputted to like 3 or 4 instead of 10? Thanks for the help.

    oh...
    you probably wanted to know how to, lol
    go to:
    http://forum.java.sun.com/thread.jsp?forum=31&thread=313399
    cheers.

  • How can i convert a double to float

    double gallons;
    double startOdometer;
    double endOdometer;
    double mpg;
    double miles;
    endOdometer = Double.parseDouble (inputs);
    miles = endOdometer - startOdometer;                                                                 
    mpg = (miles/gallons) ;
    gallons = miles/mpg;
    mpg = Float.parseFloat(double);

    You would use a cast.
    double d = 1.4;
    float f = (float) d;But why do you want to convert a double into a float and then store it back into a double?????

  • After casting double to float debugger shows wrong value

    Hi,
    My colleaque found an interesting behaviour with Java debugger. I have made some tests and here are the results:
    Test code:
    double dNum = 43.680659;
    float fNum = (float) dNum;
    System.out.println("double number = " + dNum);
    System.out.println("float number = " + fNum);This is tested in Eclipse IDE 3.4.2 with following Java JRE versions:
    - 1.4.2_19
    - 1.5.0_14
    - 1.6.0_10
    And following JDK:
    - jdk1.5.0_16
    Eclipse IDE will show following values for variables in all platforms:
    dNum = 43.680659
    fNum = 43.74316Console will print:
    double number = 43.680659
    float number = 43.68066Testing also with command line debugger jdb. Java JRE version:
    - 1.4.2_19
    And following JDK:
    - jdk1.5.0_16
    Results are the same as in Eclipse IDE. Is there a bug in debugger environment?

    I managed to find bug report of this issue:
    http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6807341
    Information:
    Bug ID : 6807341
    Synopsis : JDWP: float value reported incorrectly
    Category : java:debugger
    State : 3-Accepted, bug
    Priority : 4-Low
    Submit Date: 19-FEB-2009

  • Help!  double to float

    How can I change a double to a float?

    Hi,
    You can just cast the float as a double:
    double d = 123.4;
    float f = (float) d;
    a double has better precision so you may lose some precision when casting to a float.
    chris.

  • Java dont know subtract double or float?!!!

    The next simple java program print out Result: 6.999999999999999 when
    it should be 7. What is the reason? (i try with float 14.89 7.89 and other variations and the result is incorrect too).
    import java.io.*;
    public class subtract{
    public static void main(String argv[]){
    double n1 = 14.87;
    double n2 = 7.87;
    double result = n1 - n2;
    System.out.println("Result: "+result);
    }

    In my opinion the complexity of the internal
    operations should be transparent for the programmer.
    What i do expect is that the result of the trivial
    mathematical operations be exact. For example my
    cassio calculator do the 14.87-7.87=7 without error
    and java do not (the windows calculator give me the
    correct result, and excel too for example). How can i
    use a double in java if i know that it is not exact?Java also gives a "correct" result if you round the numbers.
    Remember that calculators are applications. They're written in some programming languages that treat floating point operations just like Java does. But the programmer has applied rounding before any result is displayed. When writing an application in Java you are that programmer.

  • Double into Float

    Hey all,
    Ive got a Double and I want to convert it to a Float and I want to check its within the IEEE 754 standards of the highest value you can have and lowest...
    But I can't parse it, as Ive found out and .floatValue() doesn't throw an error as im aware, So I was wondering if you had any ideas
       Double tmpDouble;
                            tmpDouble = new Double(anaObj.getValue());
                            float tmpFloat = 0f;
                            try
                                tmpFloat = tmpDouble.floatValue();
                            catch (NumberFormatException nfe)
                                Logger.writeLogMessage(Logger.WARNING, nfe.getMessage());
                            }

    or may need something like this, I'm not sure:
            if (tmpDouble < Float.MAX_VALUE &&
                    tmpDouble > Float.MIN_VALUE &&
                    Math.getExponent(tmpDouble) > Float.MIN_EXPONENT &&
                    Math.getExponent(tmpDouble) < Float.MAX_EXPONENT)
                tmpFloat = tmpDouble.floatValue();
            }

  • Int varialbe being automatically promoted to double or float?

    Hi everyone!
    Normally, when a int is initialized (given) a single or double precision value, the compiler will complaint...
    But why is it that the method Integer.parseInt() doesnt throw NumberformatExceptions when I input a single or double precision value in a form of string...
    Below is the code,
    import javax.swing.JOptionPane;
    public class FourPEight {
         public static void main (String[] args) {
              String gradePerStudent = "";
              int totalGrade = 0,
              averageGrade = 0;
              int studentCount = 0;
              studentCount = 1;
              //totalGrade = 0.5;
              while ( studentCount <= 10 ) {
              gradePerStudent = JOptionPane.showInputDialog("Please input grade of student " + studentCount);
                   try {
                        totalGrade = totalGrade + Integer.parseInt(gradePerStudent);
                   } catch (NumberFormatException nfe) {
                        JOptionPane.showMessageDialog(null,"Please input an integer!");
                        System.exit(0);
                   studentCount++;
              averageGrade = totalGrade / 10;
              JOptionPane.showMessageDialog(null,"The average is: " + averageGrade,"Result of computation",JOptionPane.INFORMATION_MESSAGE);
              System.exit(0);

    But why is it that the method Integer.parseInt()
    doesnt throw NumberformatExceptions when I input a
    single or double precision value in a form of
    string...It certainly should, and I just ran your code, entered the value "1.1", and a NullPointerException was thrown, resulting in my seeing the "Please input an integer!" message. If that doesn't happen for you, then you probably have a bug in your JDK.
    Perhaps the following code is easier to follow, and it certainly demonstrates that Integer.parseInt throws a NullPointerException when the value "1.1" is entered:
    public class Test {
        public static void main(String[] argv) {
            Integer.parseInt("1.1");
    }

  • What is the difference btwn double and floating data type?

    is it going to affect the computation?

    What is the difference btwn J2SDK and J2EEhttp://java.sun.com/j2se/index.jsp
    http://java.sun.com/j2ee/index.jsp

Maybe you are looking for

  • SQL QUERY COUNT PROBLEM

    Employees: Employee_ID Name 01 Hansen, Ola 02 Svendson, Tove 03 Svendson, Stephen 04 Pettersen, Kari Orders: Prod_ID Product Employee_ID 234 Printer 01 657 Table 03 865 Chair 03 SELECT Employees.Name, Orders.Product FROM Employees, Orders WHERE Emplo

  • How to change the directory where firefox stores the bookmarks

    I want to setup firefox so it will store all files, including the bookmarks, to another directory than the default directory. example d:\backup\mozilla\firefox\ This will make it easier for me to backup these files. How can I do this ?

  • Inx file from cs2 cant be saved on cs1

    I have a file created from CS2 *.inx. File size is 2.5MB. I can open the file in cs1, but can save. It hangs there. CS2 in on powermac G5, 10.3 and cs1 in on emac G4 os 10.3. I just started to supporting Mac. Im new in this area. Im more in to window

  • I don't want the date to print on photos

    Please, does anyone know how to keep the date from showing up when I print photos?

  • Emails in Reminder window disappears after sometime

    Hi Team, I am using Outlook 2013 pro plus with office 365 Email Service. My query is  I flag emails as Flag and reminder to it. After perfect time time set as reminder the reminder window pops up correctly. I have multiple reminder set. so the remind