Re: Formatting a double data type

See: http://javaalmanac.com/egs/java.text/FormatNum.html

thnx, that solved my problem, But gave rise to another.
When i have to display the result, I need in this format ##.00.
This works fine for non zero values after the decimal point. If i ahve
double d = 6.10;
NumberFormat format = NumberFormat.getNumberInstance();
System.out.println(format.format(d));
The ideally i need it to display: 6.10, but it display only 6.1.
I tried DecimalFormat too.. but couldnt find a solution. Please help.

Similar Messages

  • Java rounding for Double data type

    Hi,
    Is there a way to change the default precision to 2 digits after decimal point for Double data type.

    java.text.DecimalFormat:
    import java.text.DecimalFormat;
    DecimalFormat format = new DecimalFormat("#.00");
    StringBuffer formatted = format.format(Math.PI, new StringBuffer(), new FieldPosition(0));
    System.out.println(formatted); // prints out 3.14Probably as applicable today as it was 3 years ago

  • Error ORA-01426: numeric overflow when Creating table with double data type

    Hi,
    I am using ODP.NET to create a table with data from SQL to Oracle. The problem is with double data type fields that is equivalent to FLOAT(49) in Oracle. My syntax is:
    CREATE TABLE SCOTT.ALLTYPES
    F1 NUMBER(10),
    F10 DATE,
    F2 NUMBER(10),
    F3 NUMBER(5),
    F4 NUMBER(3),
    F5 FLOAT(23),
    F6 FLOAT(49),
    F7 NUMBER (38,5),
    F8 NVARCHAR2(500),
    F9 NVARCHAR2(500)
    Th error is with field F6 but I am not sure what is the correct type equivalent to double in SQL.
    I woul appreciate if anyone can help me with this problem.
    Sunny

    Does this simple test work for you?
    In database:
    create table float_test
      f1 float(49)
    );C# code:
    using System;
    using System.Data;
    using System.Text;
    using Oracle.DataAccess.Client;
    using Oracle.DataAccess.Types;
    namespace FloatTest
      /// <summary>
      /// Summary description for Class1.
      /// </summary>
      class Class1
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main(string[] args)
          // connect to local db using o/s authenticated account
          OracleConnection con = new OracleConnection("User Id=/");
          con.Open();
          // will hold the value to insert
          StringBuilder sbValue = new StringBuilder();
          // create a string of 49 number 9's
          for (int i = 0; i < 49; i++)
            sbValue.Append("9");
          // command object to perform the insert
          OracleCommand cmd = con.CreateCommand();
          cmd.CommandText = "insert into float_test values (:1)";
          // bind variable for the value to be inserted
          OracleParameter p_value = new OracleParameter();
          p_value.OracleDbType = OracleDbType.Double;
          p_value.Value = Convert.ToDouble(sbValue.ToString());
          // add parameter to collection
          cmd.Parameters.Add(p_value);
          // execute the insert operation
          cmd.ExecuteNonQuery();
          // clean up
          p_value.Dispose();
          cmd.Dispose();
          con.Dispose();
    }SQL*Plus after executing above code:
    SQL> select * from float_test;
            F1
    1.0000E+49
    1 row selected.- Mark

  • Issue in trusted flat file recon for usr field having double data type

    Hi
    I have a field in usr schema which is of double data type. Now when i am doing gtc trusted flat file recon the user is getting created and all fields are getting populated but field having double data type doesn't get populated.
    I have tried in other way also. After creating the user, I am trying to update that field (which is of double data type) via gtc trusted flat file update but in that case no recon event is getting generated.
    Enviroment : OIM 11.1.1.5.0
    I am stuck. Please help.

    Somebody PLEASE some idea!!!
    Any thought on the same would be really appreciated.
    Thanks in advance.

  • What is the match of float or double data type in abap?

    I have tried p, but I could not handle decimal numbers such as 10.6 or 10,6(no matter which one is preferred, the question is the same...).
    How can I handle these numbers?
    Thanks.

    Hi
    Hope you know about FLOAT and Double.But you can use the same P for handling decimal places...
    Use like this.
    Data :Deci type P DECIMALS 2.
    Get bckif you are getting error still...
    Reward All Helpfull answers..........

  • Float/double data types

    I use
    public void setId(float id) {this.id = id;}
    and
    setId(new Float(nodeNextTop.getChildNodes().item(0).getNodeValue()).floatValue());
    in my java files to get the value of a float which I want to display using
    <display:column align="center" sortable="true" nowrap="true" property="id" title="<%=id_%>" class="webText" />
    in my jsp file
    but it is displayed in true E format, ie, 1.123456789101112E15, I want to display the number as is, without the E, and it's beaten me, pls help.
    btw, double does the same

    top job, I'm learning something new each day, big thnx for the help

  • [Access 2010] Change default formats for data types

    Whenever I import data, the default format for Boolean data types is "-1,0." I know how to subsequently change this format to "Yes/No," but I'd like to change the default
    setting to "Yes/No." Is this possible?
    Thanks in advance.

    Hi,
    I found you post the same question in other place and got the advice. I agree with Mr. Kees suggestion. The data type is a build-in default setting with Access, we can't change it. We may try the workaround via VBA to test.
    http://forums.cnet.com/7723-6129_102-627633/access-2010-change-default-formats-for-data-types/#message5617496
    Please Note: Since the web site is not hosted by Microsoft, the link may change without notice. Microsoft does not guarantee the accuracy of this information.
    Have a good time.
    Regards,
    George Zhao
    TechNet Community Support
    It's recommended to download and install
    Configuration Analyzer Tool (OffCAT), which is developed by Microsoft Support teams. Once the tool is installed, you can run it at any time to scan for hundreds of known issues in Office
    programs.

  • 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

  • Table Functions, Direct Database Requests, and NUMBER data types

    Hello. I call a number of table functions from our BI Enterprise server, and I've elected to do so using Direct Database Requests (I believe you can also call table functions in the physical layer of the repository, but that's not what I'm doing). The problem is that whenever I return any number from the table function that is not a whole number (1.23, for example), BI assigns the INTEGER datatype to the field instead of the DOUBLE datatype, thereby rounding my number to the nearest integer. Here's a concise example:
    Create these 3 database objects:
    CREATE OR REPLACE TYPE my_row AS OBJECT (my_num NUMBER);
    CREATE OR REPLACE TYPE my_tab AS TABLE OF my_row;
    CREATE OR REPLACE FUNCTION my_table_function RETURN my_tab
    PIPELINED IS
    BEGIN
    PIPE ROW(my_row(1.23));
    END;
    Then make this your query in your Direct Database Request:
    SELECT my_num FROM table(my_table_function);
    That query correctly returns "1.23" when it's called from the database. In BI, on the other hand, it returns "1" (and labels the field an INTEGER instead of DOUBLE data type). If in the Direct Database Request you change the Column Properties ->Data Format -> Decimal Places from 0 to 2, it then not surprisingly displays "1.00". I then tried changing MY_ROW.MY_NUM's datatype by explicitly specifying precision, and no luck. BI still labels this field as an INTEGER. Then I started trying to trick BI by massaging the SQL statement itself. None of the following worked:
    SELECT to_number(my_num) as my_num2 FROM table(my_table_function);
    SELECT my_num2 + 0.01 as my_num3 FROM (SELECT my_num - 0.01 AS my_num2 FROM table(my_table_function));
    SELECT to_number(to_char(my_num)) as my_num2 FROM table(my_table_function);
    SELECT to_number(substr(to_char('x'||my_num),2)) as my_num2 FROM table(my_table_function);
    Now I did find a solution, but I'm surprised that I have to resort to this:
    SELECT * FROM (SELECT /*+ NO_MERGE */ my_num FROM table(my_table_function));
    Does anyone out there know of a better way to do this? The above is a hack in my opinion. :)
    Thanks in advance for any input.
    -Jim

    Yes, it's really amazing.
    But I got it.
    CREATE OR REPLACE TYPE my_row AS OBJECT (my_num NUMBER(10,2));and in your SQL :
    SELECT cast(my_num as double precision) as my_num2 FROM table(my_table_function);I have the good result and I see the numbers after the comma.
    Very tricky !
    Edited by: gerardnico on Jul 7, 2009 2:55 PM change number(10,2) by double precision ......... pfffff

  • Mapping SQL data types (especially SMALLINT) to Java classes

    I want to know the reason for a certain pair of exceptions in JDBC�s mapping of SQL data types to Java classes.
    Sun�s web site ( http://java.sun.com/j2se/1.4.2/docs/guide/jdbc/getstart/mapping.html ), Sybase�s site, and other sites contain mappings from SQL data types to Java primitive data types and/or Java classes. On that Sun web page, Section 9.9.1 maps mostly to Java primitive data types, and Section 9.9.3 maps mostly to Java classes. For the SQL data types that map to both primitive data types and classes, the class is typically the wrapper class of the primitive data type. For example, SQL�s DOUBLE data type maps to both the double primitive data type and its wrapper class (Double). However, Section 9.7 of that Sun web page says that there are exceptions for SQL�s TINYINT and SMALLINT. As expected, they map to the byte and short primitive data types, but they map to the Integer class, not the Byte and Short classes (which are the wrapper classes for byte and short). The web page does not state the reason for this pair of exceptions. It seems to me that SMALLINT data would either work for both short and Short or fail for both short and Short. I don�t see why it would work for short but fail for Short (as the web page implies).
    Can anybody think of a reason for the pair of exceptions? Thanks.

    ghs wrote:
    1) If a DBMS deals with the short and byte primitive data types (as the various web pages imply that it does), then why would it not deal with the Short and Byte wrapper classes?As another guess, because conversions get a little weird in java. Or at least they did in the past. As I recall (with not a lot of clarity) it is possible to do something like pass a perfectly valid string value into a short and get an exception. Whereas using Integer and then converting to Short works.
    Keep in mind that these are guesses.
    3) What I really want to know is this: If I use wrapper classes of Short and Byte (instead of Integer), what will be the harmful consequences (IF ANY)? So far, I have done some trivial testing with a Short for a SMALLINT column (I have not yet tried any TINYINT columns), and it seems to be working.I considered it risky to not test all target databases and drivers.
    Obviously testing will reveal problems.
    If you don't want to test then you might want to stick with integers.

  • File Adapter NFS: Doubt with th Data Type corresponding to the XML

    Hi All!!
    On my scenario, a file is caught from the server and its information is passed to a proxy.
    My doubt is how must be the XML format and the Data Type to the data be correctly retrieved?
    The XML I have designed is the next:
    Is correct? If yes, How must be defined its Data Type?
    Thanks and regards,
    Manuel Míguez.

    Hi!
    I will try to elaborate my question.
    I have the next XML Data on the Server:
    <?xml version='1.0' encoding='UTF-8'?>
    <DT_File_Req>
    <NumeroDocumento>2/0211/M015010010N</NumeroDocumento>
    <Tipo>ZEP</Tipo>
    <Version>000</Version>
    <Parcial>00</Parcial>
    <Descripciones>
    <Item>
    <Idioma>ES</Idioma>
    <DescripcionCorta>Prueba descripcion corta</DescripcionCorta>
    <DescripcionLarga>Prueba descripcion larga swfiwjeflijwelifjlwejlkfdsjfelsdjflkjdslkfjsjdoifjposdjfojsdkjfslkdjfwehjfjdslfkjsdlfhswfsdfl</DescripcionLarga>
    </Item>
    <Item>
    <Idioma>FR</Idioma>
    <DescripcionCorta>Prueba descripcion corta en frances</DescripcionCorta>
    <DescripcionLarga>Prueba descripcion larga en frances ejlkfdsjfelsdjflkjdslkfjsjdoifjposdjfojsdkjfslkdjfwehjfjdslfkjsdlfhswfsdfl</DescripcionLarga>
    </Item>
    </Descripciones>
    <Caracteristicas>
    <Item>
    <Nombre>Fecha Inicio Plano</Nombre>
    <Valor>12032008</Valor>
    </Item>
    <Item>
    <Nombre>Fecha Fin Plano</Nombre>
    <Valor>20032008</Valor>
    </Item>
    </Caracteristicas>
    </DT_File_Req>
    This XML is polled by XI.
    I have created the next Data Dype corresponding with structure of the XML (I hope will be understable):
    DT_File_Req
    Numero Documento STRING
    Tipo STRING
    Parcial STRING
    Descripciones
    Item 1..n
    Idioma STRING
    DescripcionCorta STRING
    DescripcionLarga STRING
    Caracteristicas
    Item 1..n
    Nombre STRING
    Valor STRING
    My question is if this XML structure and this Data Type are compatible. I get on SXMB_MONI an error on the Mapping and I guess that the error is produced because the XML Format is not correct.
    Thanks and regards,
    Manuel.

  • APD problem - data type & currency translation

    Hi,
    I am using APD to get hung number of records from mulitprovider. I use a query to as a source of APD.
    In the query, there is an option to select currency translation in variable screen.
    But I encounter the following problems:
    1. key figures in the output file are in floating point. is it possible to change data type in APD?
    2. when I select currency translation in this query, does APD support currency translation?
    Thanks a lot.
    Regards,
    Helen

    Hi Helen,
    You can use an routine ABAP to change the format of your data type & currency transation.
    Regards
    Romain

  • Output data type of HP34401A

    The output measurement of HP34401A is of array data type. How can I convert it to double data type?

    The output from "HP34401A Read Meas.vi" is an array of readings. You can either just extract the first element of the array or average the whole thing to get a single value.
    Also there is an alternate VI called "HP34401A Min/Max Meas.vi" that also reads the average input value. You could also try that.
    Mike...
    Certified Professional Instructor
    Certified LabVIEW Architect
    LabVIEW Champion
    "... after all, He's not a tame lion..."
    Be thinking ahead and mark your dance card for NI Week 2015 now: TS 6139 - Object Oriented First Steps

  • Smart Album : Inconsistency in the Date Type format used inside Aperture ?

    Hello,
    After using Aperture 2.0 for some days, I tried to create a Smart Album using as creation option for the Album the Date + "is in the Range" option which is leaving two blank fields for filling the two dates which are supposed to be the date limits of the pictures that the user wants to select.
    My OS X is set to the italian language so our date format is the dd/mm/yy type.
    When I tried to insert some dates in our format (dd/mm/yy) the SmartAlbum seemed to not work at all (not selecting any picture, or was coming out with weird results).
    After checking carefully that there was no filter set which could prevent the correct visualization of the pictures I had no explanation for the problem.
    At first I thought that this specific option was buggy as the other Smartalbum creation options (Keywords etc.) seemed to work properly.
    Then I had the idea and I tried to use the english format (mm/dd/yy) for the two dates inside the date range fields and to my surprise everything worked properly.
    So basically it seems that Aperture recognises the dates correctly only giving in input the american date format mm/dd/yy.
    What is not so noice is that there is no check on the date limit correctness so basically it is possible to really mess up with the dates.
    I'm also actually surprised the Aperture doesn't complies with the OS X date type which could seem the logical thing to do or at least is not consistent with the date type management inside the program because for example the pictures Dates are instead correctly listed in the List View of the browser according to the OS X date type (dd/mm/yy).
    I was wondering what is happening in countries where the date separator is not the "/" but the "." like typically used in Germany which would add another variable to the software routine which is interpreting the date input fields.....
    Maybe this could help other non english users who could have been confused like me on the same issue....
    Did you notice the same behaviour ? Am I missing something ?
    Uby

    Smart Albums will search in the Folder/Project that is shown at the top of the search HUD as well as all Folders and Projects "below" in your structure. However, it will not search through any Albums in that structure. Here is an example:
    You images are always stored in Projects (yellow icons) and lets say this is how it looks:
    FolderA/ProjectA (this Project stores: ImageA1, ImageA2)
    FolderA/ProjectB (this Project stores: ImageB1, ImageB2)
    Let us say that you have two Albums like below but there is an image from ProjectB in AlbumA, which looks like this:
    FolderA/ProjectA/AlbumA (this Album has pointers to: ImageA1, ImageA2, ImageB1)
    FolderA/ProjectB/AlbumB (this Album has pointers to: ImageB1, ImageB2)
    If you create a Smart Album below ProjectA it will only show ImageA1 and ImageA2 since it only search ProjectA and not AlbumA.
    This may be the issue you have.
    Are you 100% sure that the Project your Smart Album is pointing at does include the images you are trying to search through. As you see above then it won't find them if they are only in the albums below that project.
    Here are a few rules that I follow in order to avoid getting confused over where my images are located: A) Only include images in albums below a project that are stored in that project. B) Create all my smart albums at top library level and if necessary add extra filters like project name.
    Hope you understand.
    Karsten

  • How to Change Date-Type to Char-Type with Format?, When it.....

    I'd like to Change format Data from Date-Type Column to char-type
    especially, as 'YYYYMMDD' Format, But There are some Error Message.
    I already know, to_char(sysdate, 'yyyymmdd') from dual,
    But When it Applied my Table (has Date Type Column )....
    That SQL was Error...
    Table Description
    ===================
    GUBUN     NOT NULL     NUMBER(7)
    POLCD     NOT NULL     NUMBER(7)
    TITLE          VARCHAR2(200)
    VALUE          NUMBER(7)
    SIDATE          VARCHAR2(20)
    SQL
    ================================
    SELECT TO_CHAR(SIDATE,'YYYYMMDD') as V_SIDATE , -- <== Error
    TO_CHAR(SYSDATE,'YYYYMMDD') as V_TODAY -- <== Ok
    FROM T_POLL
    Error Msg
    ================================
    ORA-01722: invalid number
    .....I don't know Why... plz. help me, it's Urgent...-_-;
    ICQ : 40751557
    MSN : [email protected]
    Finally, sorry for my poor English...

    The reason for the error is you are applying a TO_CHAR function to a character datatype. SIDATE is a character. That field should be a date field. If for some reason, you need it to stay as a character field then you will need to change it to a date then change it back to a character.
    TO_CHAR(TO_DATE(SIDATE,'put format here'),'YYYYMMDD')

Maybe you are looking for

  • Disk Utility will not start

    Hello I need some help here. I am trying to format a new Western Digital 2tb my book essential. To do this I apparently need to open Disk Utility... but it will not open. the icon flashes for a second but then closes immediately. I have 15% of my har

  • Iweb Blog ftp or mobile me?

    I have just designed a website in iweb that I ftp through godaddy. Took a while to make that decision, but at least I have complete design control! I am doing pretty well and now at the search rankings stage and realize that iweb isn't great at that.

  • Matrix x System Form x UDO

    Hey all, I´m asking for some help to deal with the following: I want to show a new Matrix in a System Form.  The data is from a UDO (line data - detail). How should i do that ?  Can i use UDO methods ? Anyone can help me ?

  • Books are not saved when created with iPhoto 09

    When creating a book, everything is normal but the book is not saved in the computer. So I have to finish the project and order It. The name of the book is still listed on the left but there's no photos or text. I also have a book that seems corrupte

  • IPhone photos - duplicate imports

    I am using Aperture 2.1.1 I import images as managed files and change the names to a custom master name (basically my initialsyear_month_daytime). I have the "do not import duplicates" box checked. This works for my other cameras, but Aperture keeps