Float data type problem!

Hi ALL,
I have a problem with float data type. Please tell me how to fix it if you know.
THANKS!
Source code:
class testFloatType {
public static void main(String args[]) {
float i = 0.9f, j = 0.8f, k = 0.1f;
System.out.println("i = " + i);
System.out.println("j = " + j);
System.out.println("k = " + k);
System.out.println("i - j = " + (i - j));
System.out.println("i - k = " + (i - k));
Result:
i = 0.9
j = 0.8
k = 0.1
i - j = 0.099999964
i - k = 0.79999995

Hi garazdawi,
I try to use the double to instead of float, but it still has a bit error!
Source code:
class testFloatType {
public static void main(String args[]) {
float i = 0.9f, j = 0.8f, k = 0.1f;
System.out.println("i = " + i);
System.out.println("j = " + j);
System.out.println("k = " + k);
System.out.println("i - j = " + (i - j));
System.out.println("i - k = " + (i - k));
double a = 0.9d, b = 0.8d, c = 0.1d;
System.out.println("a = " + a);
System.out.println("b = " + b);
System.out.println("c = " + c);
System.out.println("a - b = " + (a - b));
System.out.println("a - c = " + (a - c));
Result:
i = 0.9
j = 0.8
k = 0.1
i - j = 0.099999964
i - k = 0.79999995
a = 0.9
b = 0.8
c = 0.1
a - b = 0.09999999999999998
a - c = 0.8

Similar Messages

  • How to configure oracle 8.1.6, 8.1.7 for recognizing float data type by  ODBC

    I know oracle recognizes float data type into the tables, and exists a parameter in the initialization parameters named NLS_NUMERIC_CHARACTER that permits to us change the presentation format. I did it, and into the server pc now it shows me '.' as a decimal point and ',' as a group separator. So, how can i do for the clients recognize the same float data type format. Which file i have to modify, or always i have to execute the instruction: alter session set NLS_NUMERIC_CHARACTERS = ".," in every client machine?
    thanks
    aldemar

    According to the National Language Support Guide, available from <http://tahiti.oracle.com>, you should be able to change the value of NLS_NUMERIC_CHARACTERS in the init.ora file for the database and have that carry across to all sessions.
    Justin

  • Reports with FLOAT data  type

    I am trying to create a simple report form from a table which contains a FLOAT data column.
    I follow these steps:
    New>Component>Report>Report with Form...
    I end up with 2-pages: the report and the entry form to update/create a row. The key-column on the report page links to the entry-form page and all values from the selected report row carry-over to the entry-form for an update with the exception of the FLOAT column. This seems to be an issue with fetching the row values when the entry-form is loaded. The FLOAT values entered manually in the form are saved. This issue is related to the FLOAT data type. When I altered the column data type to NUMBER(10,2) the value on the entry-form started appearing.

    200972,
    Our automated row fetch module (used by wizard-generated form pages) recognizes only the NUMBER datatype for numbers. I'll log this as an enhancement request.
    57434

  • Float data types

    I don't really know SSAS but have been a .NET programmer and worked with SQL Server and T-SQL for years.  I am working on a project where there is a database storing sales transactions and a cube that is created nightly so we can get MTD Sales, YTD
    Sales, Profit $, etc.
    I just ran into an issue where I got an error retrieving the Profit $ measure (using an MDX query inside of a SQL stored procedure using OPENQUERY) and found that the profit $ should be 0.07 but is coming back as 6.9999999999993179E-2. After talking
    to our DBA, he said all of the calculations in the cube are double precision floating point and I need to round all results to 2 decimal places (programs like Excel handle the rounding and I should too.)
    Our DBA also claims the measures can't be calculated and returned as currency. He claims that the potential for error is very small and no one has ever complained about a $ value being off.
    I am struggling with this answer because I have always been told never to use floating point for monetary values.  I am having a hard time believing there is no way to have a measure be a currency field that is accurate.  I looked for articles
    online but can't seem to find anything to answer my questions.
    Could someone please point me in the right direction? Thanks so much!

    Your DBA is not completely correct in his claims. All calculations are not floating point below is a link to all of the data types supported by SSAS (Multi-Dimensional)
    https://technet.microsoft.com/en-us/library/gg471558%28v=sql.110%29.aspx?f=255&MSPPError=-2147217396
    SSAS supports a currency data type. It's 4 decimal places not 2, but it is the recommended data type for currency values as it does not suffer from the imprecision of the double data type.
    The other thing measures in a cube have is the concept of a format string, so you can ask the cube to return a pre-formatted value to you. But default an OPENQUERY will just return the raw value, but if you add the following:
    CELL PROPERTIES FORMATTED_VALUE
    to the end of your MDX query that should tell it to return the formatted value (which could be something like "$#,##0.00")
    See here https://msdn.microsoft.com/en-us/library/ms146084.aspx for a list of all the different format masks that can be applied
    http://darren.gosbell.com - please mark correct answers

  • Single Line Data Type to Collection Data type, Problem in Message mapping

    I have a csv file, the file has the following lines
    hdr1
    line1
    line2
    lineN
    hdr2
    line1
    lineN
    I want it to map it to an object with the ff structure
    root object 1..1
    object 1..1
    subobject 0...n
    hdr 1..1
    line 1...n
    How is the mapping of the said data types?  Is it possible?  Please help....thanks in advance

    Hi Raymond,
    as you have two different strutures:
    - HEAD
    - ITEM
    and the occurences of the structures are not fix (say: e.g. HEADER occurs always 3 times), you need a key-field, which identifies each row as HEAR or ITEM.
    If you do not have a key-field, you must design a "generic structure" that fits to both:
    HEAD & ITEM. After the conten-conversion into this generic structure you need a message-mapping that identifies your HEADs and ITEMs.
    File content conversion sites
    /people/venkat.donela/blog/2005/03/02/introduction-to-simplefile-xi-filescenario-and-complete-walk-through-for-starterspart1
    /people/venkat.donela/blog/2005/03/03/introduction-to-simple-file-xi-filescenario-and-complete-walk-through-for-starterspart2
    /people/arpit.seth/blog/2005/06/02/file-receiver-with-content-conversion
    /people/anish.abraham2/blog/2005/06/08/content-conversion-patternrandom-content-in-input-file
    /people/shabarish.vijayakumar/blog/2005/08/17/nab-the-tab-file-adapter
    /people/venkat.donela/blog/2005/03/02/introduction-to-simplefile-xi-filescenario-and-complete-walk-through-for-starterspart1
    /people/venkat.donela/blog/2005/03/03/introduction-to-simple-file-xi-filescenario-and-complete-walk-through-for-starterspart2
    /people/venkat.donela/blog/2005/06/08/how-to-send-a-flat-file-with-various-field-lengths-and-variable-substructures-to-xi-30
    /people/anish.abraham2/blog/2005/06/08/content-conversion-patternrandom-content-in-input-file
    /people/shabarish.vijayakumar/blog/2005/08/17/nab-the-tab-file-adapter
    /people/jeyakumar.muthu2/blog/2005/11/29/file-content-conversion-for-unequal-number-of-columns
    /people/shabarish.vijayakumar/blog/2006/02/27/content-conversion-the-key-field-problem
    /people/michal.krawczyk2/blog/2004/12/15/how-to-send-a-flat-file-with-fixed-lengths-to-xi-30-using-a-central-file-adapter
    /people/arpit.seth/blog/2005/06/02/file-receiver-with-content-conversion
    http://help.sap.com/saphelp_nw04/helpdata/en/d2/bab440c97f3716e10000000a155106/content.htm
    Regards Mario

  • Getting precision length  for float data type

    Hi All,
    We trying to find the precision length of a float (126) data type. Are there any built in functions in oracle for finding the same? E.g: the function should return 5 for the value 1.23456 .
    Also, are there any table level operation to reduce the decimal precision of a float 126 field?
    Regards,
    Raj.

    Not sure if this is what you're looking for:
    select data_precision from all_tab_columns
    where owner = '<your schema name>'
    and table_name = '<your table name>'
    and column_name = '<name of column in table>';
    or are you looking for a particular find_precision_in_number() function...
    i can't think of one off the top of my head, but you can always do:
    length(substr(<colname>, instr(<colname>, '.')+1))

  • Language data type problem

    I am executing a FM from XI to create a Material with several languages in the form of ES, EN, FR and so on, what is the type that I have to use in the FM for this languages? I use a simple Char 2 type and does not work from XI but If I use SPRAS works fine, the problem is SPRAS is a Char 1 type so the system get confuse with for instance PL and PR.

    Hi
    The language in R3 is a field of 1 char, so you have to use a data type like SPRAS, if the system gets confuse I believe you need a routine to translate the language symbols from 2 char to 1 char.
    In R3 there're the table T002: here it can find both symbols: 1 char and 2 char.
    U can use the fm CONVERSION_EXIT_ISOLA_INPUT for translation:
    DATA: LANGUAGE_IN(2),
          LANGUAGE_OUT(1).
    CALL FUNCTION 'CONVERSION_EXIT_ISOLA_INPUT'
         EXPORTING
              INPUT            = LANGUAGE_IN
         IMPORTING
              OUTPUT           = LANGUAGE_OUT
         EXCEPTIONS
              UNKNOWN_LANGUAGE = 1
              OTHERS           = 2.
    Max

  • Custom Data Type Problem

    Hi,
    Im just starting in corba so his might be something simple, anyway..
    Im adapting the HelloWorld example. And in my idl interface I want to use a custom custom data type named SongPreview. I have a class file for this in the same directory as my java code.
    module HelloApp
    interface Hello
    string sayHello();
    SongPreview getFile(in String name);
    The problem is that I get an error saying that SongPreview is an undeclared type.
    Any idea what im doing wrong?
    Thanks

    Just like any other language you have to define the return
    type. In this case, it is SongPreview.
    You must define SongPreview in IDL.
    You could do it in the same IDL file or in another IDL.
    But you MUST define in IDL.
    ====================================
    Hi,
    Im just starting in corba so his might be something
    simple, anyway..
    Im adapting the HelloWorld example. And in my idl
    interface I want to use a custom custom data type
    named SongPreview. I have a class file for this in the
    same directory as my java code.
    module HelloApp
    interface Hello
    string sayHello();
    SongPreview getFile(in String name);
    The problem is that I get an error saying that
    SongPreview is an undeclared type.
    Any idea what im doing wrong?
    Thanks

  • XML data type problem

    I am trying to unflatten data from an xml file but my input type for the type on the unflatten I believe is invalid and I am getting error 1106. 
    Attached is the xml file and VI
    XML file is in text due to upload constraints
    Paul Power
    I have not lost my mind, it's backed up on a disk somewhere
    Solved!
    Go to Solution.
    Attachments:
    TestData.txt ‏2 KB
    XML Cluster.vi ‏35 KB

    Your data type cluster does not match your XML file. Fixed VI (LV version 2013) is attached. However, the file you posted appears to be a single element, not the entire file, so I cannot verify it works.
    If you have an earlier version of LabVIEW, the cluster was missing a timestamp and had a cluster at the end which should have been a string.
    Duplicate post from here.
    This account is no longer active. Contact ShadesOfGray for current posts and information.
    Attachments:
    XML Cluster.vi ‏44 KB

  • Data type problem in a table

    I have a column as
    col1 which takes the combination of numbers and alphabets
    for eg. col1=1234abc
               col1= 1234what should be the data type of the column and how to insert data in it
    Edited by: Rahul_India on Sep 7, 2012 2:11 AM
    Edited by: Rahul_India on Sep 7, 2012 2:20 AM

    Rahul_India wrote:
    I have a column as
    col1 which takes the combination of numbers and objects
    for eg. col1=1234abcDo you mean Alphabet?
    what should be the data type of the column VARCHAR2
    and how to insert data in itinsert into <table>(col1) values('1234abc')?
    If this is not what you expect, help us in helping you by reading {message:id=9360002}
    and providing relevant details.

  • Data Type Problem

    Hi to all
    I am writing a java basic program. my program is
    public class FirstJava {
         public static void main(String[] args) {
              short a,b,c;
              a=2;
              b=5;
              c=a*b;
              System.out.println(c);
    }But when i am running above program i am getting following error. FirstJava.java:8: possible loss of precision
    found   : int
    required: short
                    c=a*b;
                       ^
    1 error . Really i dont understand whats wrong with my code.
    But when i change my code from c=a*b to a*=a then its working fine. Please help me.
    Another problem, when i am trying to store 07 to a integer as int a=07; then i am getting error like value too large to store. whats wrong here. please help me..

    praveen_nlg wrote:
    Hi to all
    I am writing a java basic program.Great! Which tutorial are you following?
    But when i am running above program i am getting following error. No! You get that error when you are compiling the program. That's an important distinction and you better learn it as early as possible.
    FirstJava.java:8: possible loss of precision
    found   : int
    required: short
    c=a*b;
    ^
    1 errorPretty much all numeric calculations are done with int types in Java (except if they include float/double values).
    So "a*b" will be calculated as an int value. Then you assign it to c, which is a short. The Java compiler just tells you that you might be losing information here.
    There is almost no reason in Java to use short values, simply use int for your whole numbers and you won't run into thisissue.
    Another problem, when i am trying to store 07 to a integer as int a=07; then i am getting error like value too large to store. whats wrong here. please help me..07 should be fine, 08 will break. A leading 0 tells Java that the number is written in [base 8|http://en.wikipedia.org/wiki/Octal]. Don't do that.

  • How to handle DATE type problems in migrating from mysql to oracle.?

    Hi,
    I'm migrating only the data from mysql to oracle with the help of sql loader.But with this type i cannot able to insert the date values from mysql to oracle.In mysql i have defined date as "DATETIME" type and in oracle it is in TimeStamp.Whenever i'm inserting the values thru CTL file ,i'm getting an error invalid date format entered.How to solve this problem?
    Thanks in Advance
    JAI

    you need to supply a mask to the timestamp entry. see http://download-west.oracle.com/docs/cd/B19306_01/server.102/b14215/ldr_field_list.htm#i1006714 for details on datatypes within the ctl file
    B

  • 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.

  • Data type problems

    Hello all!
    So I'm actually writing a pretty big program that simulates the pick up sticks game, between the user and the computer...and I'm having a problem with a remove method that I made...
    when I wrote the user and computer classes, each one is supposed to remove a certain amount of sticks from the Pile( another class which I have written).
    In the Pile class, there is a method that is supposed to remove a certain amount of sticks from the pile.
    In the user and the computer class, I have this int varible maxOnATurn which is supposed to be their turn by removing the sticks from the pile..
    when i wrote
    maxOnATurn = sticks.remove(3);I got the error "int cannot be dereferenced." ....but I think all I'm using is ints when i do this...I have no idea whats wrong???? Any help is appreciated.
    Here one of the methods for the user to take a turn:
    public void takeTurn( Pile pile, int maxOnATurn)
        int sticks = pile.getSticks();
        Scanner scan = new Scanner(System.in);
        System.out.print("Please enter a number to take ( a positive integer, no more than 3):");
        int sticksTaken = scan.nextInt();
        if(sticksTaken > 0 && sticksTaken <= 3)
          maxOnATurn = sticks.remove(sticksTaken);  // here is where the error is
        else
          System.out.println(" Invalid Entry");
      }and here is the Pile class, which contains the remove method
    import java.util.*;
    public class Pile
      private int sticks;
      public Pile( int sticks)
        Scanner scan = new Scanner(System.in);
        sticks = scan.nextInt();
      public int getSticks()
        return sticks;
      public void remove(int number)
        sticks = sticks - number;
      public String toString()
        return "Sticks in Pile: " + sticks;
    }

    Right, that will make if function, but will that specifically remove the sticks from the pile???? I need to make sure it does that so other classes can use the same pile as well.
    Also,
    when I use pile.remove(int) I get another error saying "incompatible types... Found: void Required: int"

  • Oracle Long Data type Problem

    Hi,
    I am using ORACLE 7.3.4 database. I am having a problem in updating a column of long datatype in a table t1 with another column from table t2 of long datatype. I have tried setting LONG 1000000 also but this doesn't work. I appreciate any kind of suggestions.
    The error it gives is ORA-00997: illegal use of LONG datatype.
    Thanks
    Reddy

    I had the same problem too with a newest thin driver. I found that I can read all my characters (bytes) using getBinaryStream() and single-byte read(), but read() never returns -1; instead reading the character before last causes the ArrayOutOfBoundsException you mentioned.
    So I just blindly caught the exception and let it go to QA. (sort of
    InputStream r = rs.getBinaryStream(field);
    if(r == null) ...
    StringBuffer sb = new StringBuffer();
    try { for(int c = -1;  (c = r.read()) != -1;)  sb.append((char) c); }
    catch(IndexOutOfBoundsException e)
    {} // ignore Oracle idiosyncrazy.
    finally { r.close(); }
    ). Please note that getCharacterStream() or getAsciiStream() did not work for me. I did not try deprecated getUnicodeStream(): I decided I would better correctly extract characters in Java from binary data myself if I need them rather than allowing this junky thin Oracle driver to do an extra thing for me.

Maybe you are looking for

  • How can I transfer binary data from a database to another database?

    Hi all. I want to transfer binary data from a MS SQL Server 2000 to anohter SQL Server 2000. I created JDBC(table) to JDBC(stored procedure) scenario,and I uploaded a JPG image file to the sender table using the java program I developed. The JPG data

  • Migration of Fxcop Custom Rules to Visuatl Studio 2012

    I have an existing custom rule which was written in visual studio 2008 using fxocp SDK 1.35 and Microsoft.CCI 1.35. Now i am migrating it to latest version of Fxcop 11.0 and Microsoft .cci 11.0 using Vistual Studio 2012. using System; using System.Co

  • Cost of iPhone 5

    what will be the price of iPhone 5 16 GB witout contract in India after the public release of iPhone 5s and iPhone 5c??

  • Architecture Question regarding RPD (Best design practice)

    Hello, I need some design help regarding the best way to build a RPD for a Bank. Your help / guidance is greatly appreciated as always: Following is data (example) Revenue ALL (1 million record) Revenue by filter A ONLY (250k) Revenue by filter B ONL

  • MIRO invoice verification for Service entry sheet

    When trying to do invoice verification for Service entry sheet i am getting this below error pls guide me Delivery note/service entry sheet 5000000150  does not exist Message no. M8183