Float type

Hello!
Why this is happen?
float f1 = 1053.75f;
float f2 = 1052.8f;
System.out.println(f1 - f2);
Output: 0.9499512
But 1053.75 - 1052.8 = 0.95

Hi.
Check this thread.
Bye.

Similar Messages

  • Float type problem helppppppppp

    I have a jsp page, which retrieves values from a html page, my problem is that
    i can insert the values in database, but the problem is that it does not insert the flot type values...
    like 21.21, 242.52. It shows only 21,242
    it does not shows in float type.
    html form:
    <input type="text" name="code" size="5" maxlength="5">
    <input type="text" name="Description" size="65">
    <input type="text" name="DrAmount" size="12" >
    <input type="text" name="CrAmount" size="12" >
    <SELECT name="type">
    <option value="" selected></option>
    <option VALUE="C">C</option>
    <option VALUE="O">O</option>
    <option VALUE="OI">OI</option>
    <option VALUE="OR">OR</option>
    <option VALUE="S">S</option>
    <option VALUE="SB">SB</option>
    <option VALUE="SG">SG</option></select>
    <input name="pct" type="text" size="6" maxlength="5" >
    jsp page:
    <html>
    <head>
    <%@ page
         import = "java.io.*"
         import = "java.lang.*"
         import = "java.sql.*"
    %>
    <title></title>
    </head>
    <body>
    <h1></h1>
    <%
         String Code,Description,Dr_Amount,Cr_Amount,Pct,Type, sql1 ;
         ResultSet results;
         PreparedStatement sql;
         try
              Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
              Connection conn=DriverManager.getConnection("jdbc:odbc:pf","scott","ttlscott");
              try
                   int gl_code;
                   Float db_amt,cr_amt,gl_pct;
                   String gl_descr, gl_type;
                   boolean     doneheading = false;
    Statement s=conn.createStatement();
    Code = request.getParameter("code");
    Description = request.getParameter("Description");
    Dr_Amount=request.getParameter("DrAmount");               
    Cr_Amount=request.getParameter("CrAmount");
    Type = request.getParameter("type");
    Pct=request.getParameter("pct");
    PreparedStatement pstmt = conn.prepareStatement(
    ("INSERT INTO gl_mast VALUES (?, ?, ?, ?, ?,?)"));
    pstmt.setInt(1,Integer.parseInt(request.getParameter("Code")));
    pstmt.setString(2, request.getParameter("Description"));
    pstmt.setFloat(3,Float.parseFloat(request.getParameter("Dr_Amount")));
    pstmt.setFloat(4,Float.parseFloat(request.getParameter("Cr_Amount")));
    pstmt.setString(5, request.getParameter("Type"));
    pstmt.setFloat(6,Float.parseFloat(request.getParameter("Pct")));
    pstmt.executeUpdate();
                   sql = conn.prepareStatement("SELECT * FROM gl_mast WHERE gl_code = '" + Code + "'");
                   results = sql.executeQuery();
                   while(results.next())
                        if(! doneheading)
                             out.println("<table border=2>");
                             doneheading = true;
    gl_code = results.getInt("gl_code");
    gl_descr = results.getString("gl_descr");
    db_amt = results.getFloat("db_amt");
    cr_amt = results.getFloat("cr_amt");
    gl_type = results.getString("gl_type");
    gl_pct = results.getFloat("gl_pct");
                        out.println("<BODY bgColor=blanchedalmond text=#008000 topMargin=0>");
                        out.println("<P align=center><FONT face=Helvetica><FONT color=fuchsia > <BIG>GL MASTER INFORMATION</BIG></FONT></P>");
                        out.println("<P align=center>");
                        out.println("<TABLE align=center border=1 cellPadding=1 cellSpacing=1 width=\"75%\">");
                        out.println("<TR>");
                        out.println("<TD>Code No.</TD>");
                        out.println("<TD>Description</TD>");
                        out.println("<TD>Dr. Amount</TD>");
                        out.println("<TD>Cr. Amount</TD>");
                        out.println("<TD>Type</TD>");
                        out.println("<TD>Percentage</TD></TR>");
                        out.println("<tr><td>" + gl_code);
                        out.println("<td>" + gl_descr);
                        out.println("<td>" + db_amt);
                        out.println("<td>" + cr_amt);
                        out.println("<td>" + gl_type);
                        out.println("<td>" + gl_pct);
                   if(doneheading)
                        out.println("</table>");
                   else
                        out.println("No matches for " + Code);
              catch (SQLException s)
                   out.println("Dupliacte Entry<br>");
         catch (ClassNotFoundException err)
              out.println("Class loading error");
    %>
    </body>
    </html>
    error:
    HTTP Status 500 -
    type Exception report
    message
    description The server encountered an internal error () that prevented it from fulfilling this request.
    exception
    org.apache.jasper.JasperException: Unable to compile class for JSP
    An error occurred at line: 13 in the jsp file: /gl_master/gl_save.jsp
    Generated servlet error:
    D:\Program Files\Apache Software Foundation\Tomcat 5.0\work\Catalina\localhost\abhi\org\apache\jsp\gl_005fmaster\gl_005fsave_jsp.java:100: incompatible types
    found : float
    required: java.lang.Float
    db_amt = results.getFloat("db_amt");
    ^
    An error occurred at line: 13 in the jsp file: /gl_master/gl_save.jsp
    Generated servlet error:
    D:\Program Files\Apache Software Foundation\Tomcat 5.0\work\Catalina\localhost\abhi\org\apache\jsp\gl_005fmaster\gl_005fsave_jsp.java:101: incompatible types
    found : float
    required: java.lang.Float
    cr_amt = results.getFloat("cr_amt");
    ^
    An error occurred at line: 13 in the jsp file: /gl_master/gl_save.jsp
    Generated servlet error:
    D:\Program Files\Apache Software Foundation\Tomcat 5.0\work\Catalina\localhost\abhi\org\apache\jsp\gl_005fmaster\gl_005fsave_jsp.java:103: incompatible types
    found : float
    required: java.lang.Float
    gl_pct = results.getFloat("gl_pct");
    ^
    3 errors
         org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:84)
         org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:332)
         org.apache.jasper.compiler.Compiler.generateClass(Compiler.java:437)
         org.apache.jasper.compiler.Compiler.compile(Compiler.java:497)
         org.apache.jasper.compiler.Compiler.compile(Compiler.java:476)
         org.apache.jasper.compiler.Compiler.compile(Compiler.java:464)
         org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:511)
         org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:295)
         org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
         org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
    note The full stack trace of the root cause is available in the Apache Tomcat/5.0.30 logs.
    Apache Tomcat/5.0.30

                   Float db_amt,cr_amt,gl_pct;
    found : float
    required: java.lang.Float
    db_amt = results.getFloat("db_amt");The messages are self-explainatory. You are having objects of type Float. and the ResultSet.getFloat() would return float.
    Cheers
    -P

  • SQL Server 2005 - CDC problem - real / float type

    Dear Sirs,
    I test the functionality of CDC in Business Objects Data Services 4.0 (14.0.1.245).
    I am using SQL Server 2005 Developer Edition.
    I made all the steps in accordance with the Designer Guide.
    I see a table with the changes, I can change the target system using this information  but I have one problem.
    I have a problem with the real / float type.
    If I make changes in the column real / float (in the table), tha I always see the number -999.000000.
    Does anyone know how to deal with thie bug?
    Best regards,
    Michal

    Sounds very much like a bug to me. I have seen these things in the past with regular tables whenever we had an issue around regional settings. Can you change your computer locale and SQL server language to english to proof it is that and keep it as a workaround for now?

  • Parameters restriction for Float type

    I want to get a value from the user which is Float type from the selection screen. But the parameters statement doesn't allow the float type value. So please suggest me an alternative to this restriction.Please be clear in your reply as I am new to SAP.

    Well, the only alternative I can think off is to use Type P. This will not give you exponentials but will take care of the decimals.
    PARAMETERS  p_var1 TYPE LENGTH 10 DECIMALS 8.

  • Float type data not coming properly in ALDSP 2.5

    Hi,
    we are using ALDSP 2.5. We have a SQL server data base. We have created data services based on stored procs from this data base. we have a read method with a field declared as float data type. But the DSP is not showing up the correct data.
    For example,
    we get 250526.31 in DSP where as the stored proc returns 250526.32
    here are some more samples,
    DSP StoredProc
    594919.8     594919.79          
    248918.8 248918.79                              
    339514.47     339514.48                         
    322823.47     322823.48                         
    695810.8 695810.82
    694300.44     694300.42

    open a case with customer support. Attach your DSP dataspace and client, and your stored procedure definition.

  • Problem with float type display

    I have a float number, after bigger than 1E8,
    it will display as 1E8.
    How can I make it to display at 10000000?
    Thanks

    Hi!
    You may use something like:
    import java.text.*;
    double f = 123456789.9876;
    NumberFormat nf = new DecimalFormat("####.####");
    System.out.println(nf.format(f));
    I believe it is a good idea to use double for such numbers, not float.

  • How to convert an Object type to a float type????

    How do you concert something that is:
    Object [] element = new Object[20];
    into a
    float variable.
    I want to store, let say element[1] into a float variable so i can do calculations with it.
    thanks!!!!

    Well, assuming element[1] is a String, or at least that it's toString() method returns something that represents a float...
    float variable = Float.parseFloat(element[1].toString());

  • Regarding float type

    why I can't write like this
    float f = 3.506;
    where as I can write like float f = 3;

    Do a search for data width. By default any floating point decimal number is assigned 64 bits (as with double) and a whole number 32 bits (as with int). Float is a signed 32 bit floating point decimal so it isn't wide enough without an explicit call such as;-
    float f = 32.1F;
    float f = 32.1Ff; or
    float f = (float)32.1;
    As a rule of thumb make all your numbers int or double unless you have a very good reason to do otherwise

  • Float type issue

    Tyring to do a ELT Oracle DB to Oracle DB.
    IKM SQL Incremental Update.
    Source -> Float (precision 126) to Target -> Float (precision 126) is not working.
    If I remove that mapping, my ELT works.
    With that mapping, I get a vague error....
    "Too much errors in the Load step: The error limit has been reached. A maximum of 1 errors was allowed."
    I looked at the loading table C$_ and that table has the float column correctly populated.
    I looked at the integration table I$_ and that is empty. The error table E$_ is also empty.
    Any ideas anybody?
    Edited by: skhot on Dec 8, 2011 11:42 AM

    changed the IKM
    from: IKM SQL Incremental Update (row by row)
    to: IKM SQL Incremental Update.
    Its working now.

  • About the float type

    Hello,
    i have some confusion related to float variable initliazation.
    when i worte float f = 1.0;it give me an error that add the cas (float).
    bt when i worte it like float f = 1.0f then it works fine..
    i am not geeting the logic behind it.why it gave me error first time?
    can any one tell me??
    Regards,
    shruti.

    "1.0" is a double constant in Java.
    "1.0f" is a float constant.
    There is a similar thing with int/long constants:
    "1000" is an int constant.
    "1000L" is a long constant.

  • Storeing values in floate data type upto two decimal places

    Hi
    I want a float type field in my table but want to store value up to two decimal places.
    so what syntax i need to follow plz suggest.
    thanks

    it is not possible to store with Number datatype. if you are using the data to sho report, then change its format (like 45 to 45.00). if you want to store 45.00 in database, then you have to modify the datatype for that column. for this follow the following path
    1. Add a column of datatype Varchar2.
    2. Copy all the value of your number field to it.
    3. Drop the old column.
    4. However make sure that if you have used that column somewhare in arithmetic calculation, the modify it and use to_number function to do arithmetic opration.

  • Ho to set the format of an InputField of type Float

    i have a inputField(name input1),which bind to a javaBean(myBean) attribute(price: Float type).
    for example:
              myBean.setPrice(11000.42).
       but i wanna disply such a format: 11,000,420000 in my inputField of web dynpro view.
       how to set it?
       you know u cann't set to a simple type in u DD.

    Hi,
    U should have data type is same what u displayed on the view must be match then only it is possible.
    If that match the previous post is works fine.
    Other wise it shows some exception like
    com.sap.tc.webdynpro.progmodel.context.ContextException: MappedAttributeInfo(ApplicationView.Z_Rfc.Output.O_Table.price): must not modify the datatype of a mapped attribute .
    Please find this and solve your problem.
    thanks
    Lohi.

  • Choice of database column types, part 2: float(53) (or BINARY_DOUBLE) versu

    Original post in this series:
    http://forum.java.sun.com/thread.jspa?threadID=629958
    Issue #2: float(53) (or BINARY_DOUBLE) vs float(126)
    The original database design uses float(126) for several floating point type columns. Conversation with one of the database guys involved reveals that this was not a particularly conscious choice, but came when migrating an earlier database which simply used float as the column type.
    From my perspective as a Java programmer who needs to work with this data via JDBC, the choice of float(126) as a type is poor as it (a) is probably overkill, storing unneeded precision and thus wasting space (b) is unrepresentable as a Java double type unless truncation error is introduced (c) might be the cause of subtle bugs.
    Point (a) needs no further explanation.
    For point (b), note that oracle's float(53), not float(126), is the float type that best corresponds with Java's (IEEE 754) double type.
    Unfortunately, float(53) is NOT exactly equivalent to Java's double: Oracle internally uses binary coded decimal to represent numbers (float is essentially an oracle number type with added restrictions), which will not be the same bits as Java's double format (for a reference, see http://builder.com.com/5100-6388-5224536.html). This means that there can be conversion and rounding issues even when you use float(53) (see http://www.stanford.edu/dept/itss/docs/oracle/9i/java.920/a96654/oraint.htm#1000888 which states "Performing mathematical manipulations of the data directly in SQL format avoids the loss of precision that occurs in converting between SQL and Java formats").
    For point (c), here is an example of how I think that subtle bugs can be introduced. Suppose that you do a query and among the results is some floating point type, internally stored in the db as float(126) but which can only be represented in a normal computer language program by a double type, which is equivalent to a float(53). (No one wants to use a class like Java's BigDecimal if at all possible because it is very awkward to use and is extremely slow as well.) So truncation has to occur. Then suppose that the programmer wishes to use that floating point value, unmodified, as part of a subsequent query, say in an equals condition. But now it may not equal because the value in his program has lost information present in the original, so the query does not work as expected. Of course, for this scenario, one could query based on "approximately equal" instead of exactly equal. But that assumes that the programmer knows to do this, and then even if he does, it is a pain to write, may be a performance hit, and subjectivity is involved (e.g. in how much being off you will tolerate). So, if it is at all possible to reasonably avoid this, yuo want to.
    It appears that Oracle 10g now offers the BINARY_DOUBLE type which DOES exactly correspond to Java's double type; see http://builder.com.com/5100-6388-5224536.html
    What are people's thoughts on the points that I raise above: is using a float(126) a suboptimal design choice, or are there no significant issues?
    Anyone have experience with the new BINARY_DOUBLE type? (Unfortunately, we are currently using Oracle 9i so this may not be an option for us.)

    Original post in this series:
    http://forum.java.sun.com/thread.jspa?threadID=629958
    You could have posted it as a reply to that post. :)
    It's difficult managing to keep multiple posts close together.

  • Converting Float to P type without rounding

    Hello people,
    I'm looking for a function, or even a pease of code to convert F variables to P variables without rounding the value.
    Thanks alot,
    Daniel Marchena
    Edited by: danielmp on Nov 28, 2011 1:22 PM

    Thank's a lot everyone.
    The following code solved my problem:
    REPORT  ZNAME.
    DATA: FLOAT         TYPE f,
               PACKED(15) TYPE p DECIMALS 3.
    DATA: GV_STR TYPE STRING,
                GV_STR1 TYPE STRING,
                GV_STR2 TYPE STRING.
    GV_STR = FLOAT.
    SPLIT GV_STR AT '.' INTO GV_STR1 GV_STR2.
    CLEAR GV_STR.
    CONCATENATE GV_STR1 '.' GV_STR2+0(3) INTO GV_STR. " here in this step 3 is the number of decimals you wish to have
    PACKED = GV_STR.
    WRITE PACKED.

  • How to enter a floating value in a custom table.

    hello guys,
    I have created a custom table, the table has a field of type fltp(floating type) now when i create a maintanence genrator, this field is not displayed in the maintenance generator screen.
    Can any one suggest me what is the reason ? also how to enter the values in this scenario.
    Regards
    Abhinav

    When I Recreated your problem i got this message.
    Field ZTEST_FGLG-QTY can not be displayed on screen 0001
         Message no. SV617
    Diagnosis
         The field ZTEST_FGLG-QTY can not be offered for maintenance on the
         screen 0001, for technical reasons.
    System Response
         The generation continues, but the field ZTEST_FGLG-QTY does not appear
         on the screen 0001.
    From the message it is clear that it is not possible to show the field on screen.
    so you have to use either some Decimal Field or Qty field instead of FLTP field.

Maybe you are looking for