Setting precision value of float/double

Hi,
I am retrieving data from database in to a float/double datatye. when i display the value it is showing the decimal of 4 to 5.(ex:4325.65785) but i want to display it as (ex:4235.65).
Thanks
Gopi

import java.text.DecimalFormat;
public class FormatTest
     public static void main(String[] args)
          DecimalFormat df = new DecimalFormat("##0.00");
          double d = 123456.2345678;
          System.out.println("Formatted: " + df.format(d));

Similar Messages

  • Precision loss - conversions between exact values and floating point values

    Hi!
    I read this in your SQL Reference manual, but I don't quite get it.
    Conversions between exact numeric values (TT_TINYINT, TT_SMALLINT, TT_INTEGER, TT_BIGINT, NUMBER) and floating-point values (BINARY_FLOAT, BINARY_DOUBLE) can be inexact because the exact numeric values use decimal precision whereas the floating-point numbers use binary precision.
    Could you please give two examples: one where a TT_TINYINT is converted to a BINARY_DOUBLE and one when a TT_BIGINT is converted into a DOUBLE, both cases give examples on lost precision? This would be very helpful.
    Thanks!
    Sune

    chokpa wrote:
    Public Example (float... values){}
    new Example (1, 1e2, 3.0, 4.754);It accepts it if I just use 1,2,3,4 as the values being passed in, but doesn't like it if I use actual float values.Those are double literals, try
    new Example (1f, 1e2f, 3.0f, 4.754f);

  • Trouble with doubles (adding, setting precision)

    Firstly,
    I have a loop that adds 0.3 three times. For some reason it comes out as .8999999999999!
    Why is this?
    Second, does anyone know where I can download a class or view source code that allows you to set decimal precision of a double? I started writing one myself but it's more complex than I thought and I'd rather just use someone elses if I could...

    The precision of calculations and how numerical
    floating point numbers are handled in computers are is
    very relevant for business situations. Actually the
    problems with decimal numbers themselves often need to
    be understood by those creating the business rules (ie
    like the sales people, audit departements, CEOs, etc.)
    The precision of the java double itself is unlikely to
    ever have an impact on that though.
    For example, if a business person asks you to
    calculate a mortgage payement then they must
    understand exactly the impact that the imprecision of
    such decimal calculations will have on the business.
    And they must understand it enough so that they can
    decide the correct way for handling it. The rules
    for handling this case, at least in the
    mortgage/banking industry, is going to be far less
    the possible precision that a java double can have.
    (The reason of course being that how this is handled
    d impacts the credits of the lender and the debits of
    the lendee.)
    Given the above it matters little what data types are
    used to handle the calculation itself. But rather
    that the calculation is done in such a way that the
    business people understand it and that they understand
    the limitations of it as well.Okay, I don't disagree with any of that. Still not sure about your overall point though.
    * P-L said "don't add doubles in a loop because it compounds rounding errors."
    * I said "but if the number of addtions multiplied by the maximum error is still within your error tolerance, it's okay." In other words, Java's double's precision is not necessarily going to be a problem.
    * You said some things that seem to agree with that final point, but your "that is fine if your job consists of nothing but evaluating computers, but for the rest of us the errors in the data that we are using..." comment makes it sound like you're disagreeing with my point: "The errors in Java's double may not cause you problems. Know it's limitations, and how they relate to your requirements."
    Are you looking for an argument, now that "one exit point" has fizzled? :-) Or am I just being particularly dense today?
    ¶

  • Converting array of Double Precision values to U16 for MODBUS

    Hello,
    I am trying to send over pressure and temperature information via the Input Register array in MODBUS TCP.  My question is, how to I properly send over an array of double precision values without loosing my data?
    For example, my array of data looks like:
    12.0001
    32.001
    0.00051234
    0.0014838
    1.02
    12.0232
    31.920
    Thanks so much.

    Thank you Ravens Fan for replying.
    I missed one extra point of data.  Below is what I'd like to send:
    12.0001
    32.001
    0.00051234
    0.0014838
    1.02
    12.0232
    31.920
    2046
    The array above is an array of double precision values.  I will convert that array to an array of single precision floating data to reduce data size.
    Since I have eight pieces of single precision floating point data now, I will need to write to 16 registers correct?  What is the best method to split up each piece of data into two consecutive registers?
    Attached is a Slave Send Data.VI that I want to send this data through.  The end goal is to have a Master PC (not using labview, but a MODBUS utility) to read my MODBUS TCP message from the "Slave Send Data.vi" 
    Thanks
    Attachments:
    Slave Send Data.vi ‏15 KB

  • How do i convert a float value to a double value?

    How do i convert a float value to a double value? HELP PLEASE!! im very stuck!! i gota float data type and i need to convert it to a double data type in order to use it in another operation.....
    thank u so much!

    safe dint realise ppl were so arrogant. thanks for the reply but less of the sarcasm!

  • Setting precision to primitive data types

    How can I set precisions to the primitive data types, viz, double and float??
    I'm writing a program in which I've declared a double variable as follows :
    double d=12.00
    System.out.println(d);
    The output is 12.0 but I want it to be 12.00
    How can it be done??

    You have to use a BigDecimal:
            BigDecimal bd = new BigDecimal(12);
            bd = bd.setScale(2, BigDecimal.ROUND_HALF_UP);
            System.out.println(bd);

  • Float - double == loss of accuracy?  why?

    The following test fails:
    public void testFloat() {
            float number = 46702.45F;
            Float numberAsFloat = new Float(number);
            double numberAsDouble = numberAsFloat.doubleValue();
            System.out.println(numberAsDouble);
            assertTrue(46702.45 == numberAsDouble);
    }I probably just don't understand floating point data types or something, but I was very surprised that this test fails. If someone could enlighten me on WHY this fails, I would really appreciate it. For what it's worth, the value printed out for numberAsDouble was 46702.44921875 which I find entirely unexpected considering I am going from a lower precision data type (float) to a higher precision data type (double).

    Remember: the floating point representations (float and double) store binary values. Not decimal. The decimal values are parsed by the compiler and turned into floats and doubles in binary.
    The said binary values are approximations to the decimal values. Sometimes the binary and the decimal values coincide, but some times they don't.
    Floats have less precision than doubles.
    The binary string that represents that number, in a float, will be interpreted differently in a double, because the double has those additional bits of precision.
    Consider this code:
        double nd = 46702.45d;
        float nf = 46702.45F;
        long ndl = Double.doubleToLongBits(nd);
        long nfl = Float.floatToIntBits(nf);
        long nfl2 = Double.doubleToLongBits(nf);
        System.out.println(Long.toBinaryString(ndl));
        System.out.println(Long.toBinaryString(nfl));
        System.out.println(Long.toBinaryString(nfl2));It prints this:
    100000011100110110011011100111001100110011001100110011001100110
    1000111001101100110111001110011
    100000011100110110011011100111001100000000000000000000000000000
    // now I add spaces to line up the various segments
    // sign   exponent  mantissa
         1 00000011100  110110011011100111001100110011001100110011001100110
         1    00011100  1101100110111001110011
         1 00000011100  110110011011100111001100000000000000000000000000000Look at that string of "0011"'s on the version of the number created as a double.
    Compare it to the 0's in the version that was created as a float and used as a double.

  • Error while setting Minimum value to  Input Number Spin Box..

    Hai
    I drag and drop a VO and created a table.In that table,i convert a column which contain an InputText field to Input Number Spin Box.At the time of page load ,the table fetches the datas from the DataBase and showing Number values in the SpinBox.After that,When i scroll the table through vertical scrollBar,the table showing *"fetching data"* and Error is throwing as *"The value must be Number"* .. In the VO,this attribute is Number.
    THIS ERROR ONLY OCCURS when i set the Minimum value of spinBox ..The purpose of setting minimum value is that i only want user to select ve value only..How can i restrict the user for selecting only ve values..?(ie,*How can i set minimum value to SpinBox?)*

    Try changing the datatype of your attribute in the EO to be Double instead of Number.

  • HOW to set the value attribute of FORM INPUT data to a variable in a JSP

    eg. Registration.jsp
    The data is accessed from an hidden field called course
    for example, if I have "Java programming" in the field course, and I use
    an expression to access the value from the hidden field.
    **My problem is that the data gets truncated to "Java" , I need "Java Programming"to display. The code looks like this
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <INPUT TYPE="text" SIZE=12 NAME="course"
    VALUE=<%=getParameter("course") %>
    IS there ANY OTHER WAY to set the value of VALUE to a variable?

    Instead of value=<%=request.getParameter("course")%>
    Use double codes
    value="<%=request.getParameter("course")%>"

  • Set default value for price unit when creating material master data

    HI: Every
    could you tell me how to use user-exit or else ways to set default value(such as 1000) for field "Price unit" (MBEW-PEINH) when creating material master data(MM01)?
    I have try to use Exit:EXIT_SAPLMGMU_001. However, this way cannot respones it.
    thanks
    Henry

    Hi: Ihave find out a solution
    Use BADI: BADI_MATERIAL_REF
    SPROlogistics general enhancement supplement or change default data (industry)
    And then creating a Implementation Name
    Double click method: CREATE_MATERIAL
    And then write code as below:
    method IF_EX_MATERIAL_REFERENCE~CREATE_MATERIAL.
              c_mbew-peinh = '1000' .
    endmethod.
    However, SAP still store '1000' in database evenif we change the default value such as 100 when we use TCode MM01.
    in additional, we still use MM02 to change the default value such as '100'
    can anybody tell me how to do?
    thanks
    Henry

  • How to remove precision value in oracle table

    Hi,
    I have created one table ,that table contains 40 million records and some of the columns containing precision values and the columns are of datatype is NUMBER...
    I need to remove precision values of those columns for 40 millions records which ever contains ,If I use update truncate scripts it's taking so long time to update ( for .eg. more than 2 weak to update --- update table_name set transaction_id=trunc(transaction_id) ).Is there any other way...
    so can you please suggest ....
    Thanks,
    vidhya

    hi marcopb,
    Below I have mentioned some columns in bold, which i am updating . yes it's taking to update more than 2 weak not yet finished...
    My update script is Update Inv.Mtl_Material_Transactions Set Transaction_Id=Trunc(Transaction_Id),Transaction_Action_Id=Trunc(Transaction_Action_Id),
    Transaction_Source_Id=Trunc(Transaction_Source_Id),Rcv_Transaction_Id =Trunc(Rcv_Transaction_Id );
    describe mtl_material_transactions;
    Name Null Type
    TRANSACTION_ID NOT NULL NUMBER
    LAST_UPDATE_DATE NOT NULL DATE
    LAST_UPDATED_BY NOT NULL NUMBER
    CREATION_DATE NOT NULL DATE
    CREATED_BY NOT NULL NUMBER
    LAST_UPDATE_LOGIN NUMBER
    REQUEST_ID NUMBER
    PROGRAM_APPLICATION_ID NUMBER
    PROGRAM_ID NUMBER
    PROGRAM_UPDATE_DATE DATE
    INVENTORY_ITEM_ID NOT NULL NUMBER
    REVISION VARCHAR2(3)
    ORGANIZATION_ID NOT NULL NUMBER
    SUBINVENTORY_CODE VARCHAR2(10)
    LOCATOR_ID NUMBER
    TRANSACTION_TYPE_ID NOT NULL NUMBER
    TRANSACTION_ACTION_ID NOT NULL NUMBER
    TRANSACTION_SOURCE_TYPE_ID NOT NULL NUMBER
    TRANSACTION_SOURCE_ID NUMBER
    TRANSACTION_SOURCE_NAME VARCHAR2(30)
    TRANSACTION_QUANTITY NOT NULL NUMBER
    TRANSACTION_UOM NOT NULL VARCHAR2(3)
    PRIMARY_QUANTITY NOT NULL NUMBER
    TRANSACTION_DATE NOT NULL DATE
    VARIANCE_AMOUNT NUMBER
    ACCT_PERIOD_ID NUMBER
    TRANSACTION_REFERENCE VARCHAR2(240)
    REASON_ID NUMBER
    DISTRIBUTION_ACCOUNT_ID NUMBER
    ENCUMBRANCE_ACCOUNT NUMBER
    ENCUMBRANCE_AMOUNT NUMBER
    COST_UPDATE_ID NUMBER
    COSTED_FLAG VARCHAR2(1)
    INVOICED_FLAG VARCHAR2(1)
    ACTUAL_COST NUMBER
    TRANSACTION_COST NUMBER
    PRIOR_COST NUMBER
    NEW_COST NUMBER
    CURRENCY_CODE VARCHAR2(10)
    CURRENCY_CONVERSION_RATE NUMBER
    CURRENCY_CONVERSION_TYPE VARCHAR2(30)
    CURRENCY_CONVERSION_DATE DATE
    USSGL_TRANSACTION_CODE VARCHAR2(30)
    QUANTITY_ADJUSTED NUMBER
    EMPLOYEE_CODE VARCHAR2(10)
    DEPARTMENT_ID NUMBER
    OPERATION_SEQ_NUM NUMBER
    MASTER_SCHEDULE_UPDATE_CODE VARCHAR2(10)
    RECEIVING_DOCUMENT VARCHAR2(10)
    PICKING_LINE_ID NUMBER
    TRX_SOURCE_LINE_ID NUMBER
    TRX_SOURCE_DELIVERY_ID NUMBER
    REPETITIVE_LINE_ID NUMBER
    PHYSICAL_ADJUSTMENT_ID NUMBER
    CYCLE_COUNT_ID NUMBER
    RMA_LINE_ID NUMBER
    TRANSFER_TRANSACTION_ID NUMBER
    TRANSACTION_SET_ID NUMBER
    RCV_TRANSACTION_ID NUMBER
    MOVE_TRANSACTION_ID NUMBER
    COMPLETION_TRANSACTION_ID NUMBER
    SOURCE_CODE VARCHAR2(30)
    SOURCE_LINE_ID NUMBER
    VENDOR_LOT_NUMBER VARCHAR2(30)
    TRANSFER_ORGANIZATION_ID NUMBER
    TRANSFER_SUBINVENTORY VARCHAR2(10)
    TRANSFER_LOCATOR_ID NUMBER
    SHIPMENT_NUMBER VARCHAR2(30)
    TRANSFER_COST NUMBER
    TRANSPORTATION_DIST_ACCOUNT NUMBER
    TRANSPORTATION_COST NUMBER
    TRANSFER_COST_DIST_ACCOUNT NUMBER
    WAYBILL_AIRBILL VARCHAR2(20)
    FREIGHT_CODE VARCHAR2(30)
    NUMBER_OF_CONTAINERS NUMBER
    VALUE_CHANGE NUMBER
    PERCENTAGE_CHANGE NUMBER
    ATTRIBUTE_CATEGORY VARCHAR2(30)
    ATTRIBUTE1 VARCHAR2(150)
    ATTRIBUTE2 VARCHAR2(150)
    ATTRIBUTE3 VARCHAR2(150)
    ATTRIBUTE4 VARCHAR2(150)
    ATTRIBUTE5 VARCHAR2(150)
    ATTRIBUTE6 VARCHAR2(150)
    ATTRIBUTE7 VARCHAR2(150)
    ATTRIBUTE8 VARCHAR2(150)
    ATTRIBUTE9 VARCHAR2(150)
    ATTRIBUTE10 VARCHAR2(150)
    ATTRIBUTE11 VARCHAR2(150)
    ATTRIBUTE12 VARCHAR2(150)
    ATTRIBUTE13 VARCHAR2(150)
    ATTRIBUTE14 VARCHAR2(150)
    ATTRIBUTE15 VARCHAR2(150)
    MOVEMENT_ID NUMBER
    TRANSACTION_GROUP_ID NUMBER
    TASK_ID NUMBER(15)
    TO_TASK_ID NUMBER(15)
    Thanks,
    vidhya

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

  • PreparedStatement.setFloat does not enter precise values into database

    Hi
    I have written a program where I am entering a record in to the
    database using a prepared statement. The problem is for float datatypes, the
    values being entered into the database are not rounded off. e.g. 1.65 is
    being entered as 1.64999999
    I am using the Sybase database and the driver is
    com.sybase.jdbc2.jdbc.SybDriver.
    If I replace PreparedStatement with Statement I am getting the precise values
    Regards
    Sudeep

    SOME THINGS YOU SHOULD KNOW ABOUT FLOATING-POINT ARITHMETIC
    What Every Computer Scientist Should Know About Floating-Point Arithmetic
    Beat yawmark to it :-)

  • How can I compute a very precise value for e?

    So I've been looking around for a good algorithm to compute a very precise value for e. All the algorithms I've found all use a derivative of the old summation from 1->n of 1/n!. And this is accurate, however I need to calculate e out to several thousand decimal places and you simply cannot accuratly represent something of that precision with a common floating point variable.
    Basically what I need is a method to seqentially calculate one decimal place at a time, or some kind of spigot algorithm where I can calculate a single nth decimal place. I've tried googling and searching these forums without any luck. I know there are spigot algorithms for PI and that there are ways to relate PI to e so maybe I'll have to use a combination of those. Anyone got any ideas?

    No it is not at all difficult to find the prime. And forgive me for being overly terse and jumping to conclusions in my posts. If I am wrong in my assumptions, I apologize. For thoses of you that are not following any of this, here is the back story:
    I read in the newspaper yesterday that someone had placed a billboard ad that was a puzzle somewhere in sillicon valley specifing something like
    [the first 10 consecutive digits in the decimal expansion of e that form a prime].com
    I don't live in California and have not seen the ad and may have mis quoted it.
    The article went on to say that Google had placed the ad, and that if you get the proper number and type it in you get to page that lists another puzzle. If you follow the chain of puzzles to the end you get an invite to submit a resume to Google.
    I look at the forms this morning and find a post from someone that was thinking about needing e out to a large number of digits. When a practical method was suggested in the reply the OP points out that this is not for some "practical" purpose but for some "theoretical" purpose. I jumped to the conclusion that this was someone that wanted to solve the puzzle but didn't want to work to hard to do it.
    My comments that the first 10 digit prime is 99 digits into the expansion it quite possibly irrelevant to the OPs original question. If there was some other "theoretical" purpose that requires some 800 Million digits of e, I apologize for my assumptions.
    On the other hand if the OP just wanted to solve the Google puzzle, why not come clean, admit it, and tell us the problem that you want to solve rather than beating around the bush with nonsense about needing an algorithm that pops out the nth digit of e. I've already given you the spoiler of where it is in the expansion of e, If you want the rest of the spoiler, like what the digits are, and what the answer to the next question is as well, just ask.
    Here is the BigInt Code
        BigInteger fac = BigInteger.ONE;
        BigInteger n = BigInteger.ONE;
        BigInteger scale =(new BigInteger("10")).pow(200);
        acc = scale; // this is the n=0 term because 0!=1
        int numTerms = 0;
        boolean done = false;
        while(!done){
          BigInteger nextTerm = scale.divide(fac);
          acc = acc.add(nextTerm);
          numTerms++;
          if (nextTerm.equals(BigInteger.ZERO)) done = true;
          //System.out.println(numTerms+":fac"+fac);
          n = n.add(BigInteger.ONE);
          fac = fac.multiply(n);
        System.out.println("Number of terms:" + numTerms);
        System.out.println("e to about 200 digits:" + acc);Go nuts!

  • Setting default values at the start of a process

    Hello
    I need to set some constant values to the attributes in data object as soon as start event of a process is triggered.
    How can I do that?
    Regards
    Vidyadhar

    Vidyadhar,
    Follow the below procedure to set Default Values
    1.Right Click on Start Event select Properties
    ->Goto Output Mapping Tab
    ->Double Click on Element on which you want to give Static Value
       and enter the value with double codes for eg: "Name"
    Make sure that this element value should be  has a Input to the next level.
    Thanks
    Srikanth

Maybe you are looking for

  • Ipod mini click wheel

    I bought my ipod mini in june, and by mid july, the click wheel all of a sudden was at an angle, i mean the wheel itself was slanting to the left, towards the back track button. I never put much, or any force on my ipod mini click wheel, especially s

  • Alt+Ctrl+Del on windows?

    On windows, you can bring up a screen by press Alt, Ctrl, Del to quit programs or end process and i was wondering if there is something similar to that in Mac and how i could go about getting to that, thanks

  • Encoding a FLV file to MP4

    I am relatively new to Adobe and all of its products, and this is my first exposure to Media Encoder CS5. Quite simply I would like to encode a FLV file to MP4. When I drag the FLV file into AME, it tells me "The source compression type is not suppor

  • How to play cd collection on itv

    I have a Large collection of cds stored on my external hard drive. I can bring them up on itv but they only ply for a couple of seconds! What's going on and can this be fixed?

  • Willing deleting cache help make a better dvd

    There doesn't seem to be a resolution to improving the clips that look like they don't have enough pixels & sort of mov in & out. They look fine in the IM08 project & in QT but on IDVD player & when I make a dvd, the same clips look like a tv censor