String double conversion

I got a big trouble converting double values to strings and viceversa.
Look a the code
          String amountString = "0.288";
          double amount = Double.parseDouble(amountString);
          amount *=100;
          System.out.print(amount);
This computation leds to the resulting amount: 28.799999999999997!
thats quite different from "0.288".
Has someone some idea what's happening?
thanks

And who is the slowest old sod again? ;-)But you managed to post a fancy link. :)Yup, so virtually I was first ;-) Seriously though: this forum needs
a FAQ list. This question has been asked more than often, in one
variation or another. If I'm not mistaken the usenet comp.lang.java.*
hierarchy has a FAQ list. Maybe that one would be a fine link to
pass around.
kind regards,
Jos

Similar Messages

  • String to 2D string array conversion

    Hi,
    I have a string like this below. I would like to extract all the texts within the quotes "  ". How to do that?.
    05-Mar.20:52   skalyana    label type "BASELINE_1.2" (locked)
    28-Apr.19:19   skalyana    label type "BASELINE_1.8"
    i have tried using Match regular expression. I am able to extract one text within " ".
    I would like to know how to extract all the text within " "
    I have attached the vi for your reference
    Thanks
    Kalyan
    Attachments:
    string to 2D string array conversion.vi ‏19 KB

    Hi Jim,
    its simply superb...
    how to get more info on these 'Regular Expressions', is there any KB (knowledge base) or tutorial available for the same.
    I am not allergic to Kudos, in fact I love Kudos.
     Make your LabVIEW experience more CONVENIENT.

  • HELP: String to double conversion?

    Hello,
    I want to convert a String to a double, and then use this double for a calculation. The conversion seems to be ok, but I get an error with the calculation... Please HELP!
    A part of my code:
    double angle;
    Double converted_angle;
    angle=jTextField2.getText();
    converted_angle= Double.valueOf(angle);
    double theta = cos(Math.PI/180*converted_angle);
    ERROR: "operator * cannot be applied to double,java.lang.Double"
    Thanks in advance.

    This is happening because you want to multiply a Double object, instead of a double value. Do this:
    Double converted_angle; should be double converted_angle;
    converted_angle= Double.valueOf(angle); should be changed to converted_angle = Double.parseDouble(angle);
    angle should probably be a String.
    check this link for your options:
    http://java.sun.com/j2se/1.4/docs/api/java/lang/Double.html

  • String exponent number to integer and double conversion

    Anyone who can help please,
    I am receiving data back from an Agilent E4407B with the noise figure option in the following form:
    +1.00000000E+008,+1.52799997E+001,+1.00000000E+009,+1.52200003E+001,+2.00000000E+009,+1.51099997E+001,+3.00000000E+009,+1.50799999E+001,
    for up to 401 pairs of frequencies and amplitude figures.  This is all coming back in one long string.
    I want to read the pairs of figures into a 2 dimensional array, so that the first part of the array has the frequency in an double format, but NO exponent, and the second part of the array has the ENR value agan in a double format and also with NO exponent.
    I have been using:
    double ENR_Data[401][2];
    Scan(Databuf,"%s>%401f[x]",&ENR_Data);
    This reads the data into the array, but retains the exponent - please can someone show me the correct Scan formatting functions to use so that I keep just the number, and loose the scientific exponent format?
    Many thanks for any help,
    Allen Cherry

    Allen:
    It doesn't matter how you represent the doubles: the compiler represents them the same.
    double a = 2000000000.00;
    double b = 2e9;
    As far as the compiler is concerned (and as far as you should be concerned), a==b.
    In your last reply, your interpolated value of (say) 25000000000 = 2.5e10, which is greater than 2e9 and 3e9.  You said you may have the wrong number of zeros in the example, but please make sure you have the right number of zeros in your code.
    Are you sure you are handling the array correctly?  Remember that the array subscripts are [row][column].  From your sample data, the frequency values are in column 0.  The first frequency value would be ENR_Data[0][0].  The second frequency value would be ENR_Data[1][0], followed by ENR_Data[2][0], etc.
    Check the code I included below.  It's based on the numbers shown in your example.  It correctly determines if a number is greater than or less than a desired interpolated point.
    P.S. What algorithm are you using to do you interpolation?  I don't even know why you are searching for a number greater than some known value: you should be interpolating between points read from the array.
    #include <ansi_c.h>
    #include <utility.h>
    #include <formatio.h>
    main()
     char Databuf[] = "+1.00000000E+008,+1.52799997E+001,+1.00000000E+009,+1.52200003E+001,"
         "+2.00000000E+009,+1.51099997E+001,+3.00000000E+009,+1.50799999E+001";
     double ENR_Data[401][2];
     double interpValue = 2.5E9;
     // same as
     // double interpValue = 2500000000.00;
     int i;
     Scan(Databuf,"%s>%401f[x]",&ENR_Data);
     for (i=0; i<4; i++)
      if (ENR_Data[i][0] > interpValue)
       printf("%f (%e) > %f (%e)\n",
        ENR_Data[i][0], ENR_Data[i][0],
        interpValue, interpValue);
      else
       printf("%f (%e) <= %f (%e)\n",
        ENR_Data[i][0], ENR_Data[i][0],
        interpValue, interpValue);
     printf("Press any key to continue...\n");
     GetKey();

  • LV RT - String to double conversion

    Hello,
    I want to convert a string to a double on my Real Time device (PXI-8101. When I use the "scan value" or "Fract/Exp String To Number Function" VI the numbers after comma dissapear. This does not happen on the Host (PC). 
    So for example on the host vi, the string "2121,3" gives the number 2121,3. If I do the same thing on the Real Time, the string "2121,3" returns the number 2121. 
    How can I fix this?
    Thanks in advance,
    Regards,
    Dries
    Solved!
    Go to Solution.
    Attachments:
    String2Number.vi ‏7 KB

    Hello,
    Thanks for the reply, but scan from string also does not return the correct number on the RT device. The VI returns the number after comma as the remaining string. Any other suggestions?
    Best regards,
    Dries
    Attachments:
    String2Number.vi ‏8 KB

  • String to double conversion, but keeping leading zeros?

    Hopefully a simple one for you gurus,
    double theValue = Double.parseDouble(aString);works fine, but the input string is say, "08.00", then theValue = 8.0, I want 08.00, how would I go about implementing this?
    tia.

    You will get ur question answered at the following webpage:
    http://java.sun.com/docs/books/tutorial/java/data/decimalFormat.html
    --DM                                                                                                                                                                                                                                                                               

  • Remove .00 from string while conversion

    How do i remove .00, .01 from the string while converting that string to int
    i tried to do this
    Select REPLACE(CONVERT(varchar(15), [Cases], 1), '.00', '') from table
    UPDATE table
    SET [CASES_d] = CAST(REPLACE(CONVERT(varchar(15), [Cases], 1), '.00', '') AS INT)
    I get the error
    Conversion failed when converting the varchar value '1.10' to data type int.
    can somebody help
    Thanks

    Sorry, in that code I missed intermediate conversion into decimal(10,2). I forgot we can not convert directly.
    So, try:
    update table set cases_id = case when cases like '%[^0-9.]%' then 0 else cast(cast(Cases as decimal(10,2)) as int) end
    where cases not like '%[^0-9.]%' -- exclude updating bad rows
    For every expert, there is an equal and opposite expert. - Becker's Law
    My blog
    My TechNet articles

  • Masterdata upload - Add string after conversion

    Hi experts,
    I upload masterdata from BW using transformationfile and conversionfile. To create a BPC specific ID I need to remove the leading zeros first (using js:parseInt in conversion) and afterwards I need to add a string (VK) at the end of the ID. How can I do that. Using *Str(VK) in transformation will lead to an error as the js:parseInt statement in the conversion file will no longer work.
    Any help appreciated.
    Thanks in advance
    Felix

    Hi Flex,
    You can achive this by using end routine badi.
    LOOP AT <lt_data_im> ASSIGNING <ls_data>.
    Get ID value
    ASSIGN COMPONENT `ID` OF STRUCTURE <ls_data> TO <lv_id>.
    IF sy-subrc <> 0 OR <lv_id> IS INITIAL.
    CONTINUE.
    ENDIF.
    CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'
        EXPORTING
          INPUT  = <lv_id>
        IMPORTING
          OUTPUT = <lv_id>.
    Concatenate your string to <lv_id>
    ENDLOOP.
    Thanks & Regards,
    Kalyan Undavally.

  • String/number conversion

    I am trying to convert a number in a string (a SPICE netlist) to a double. The string contains extra letters. Is there a String or double (or float) method that safely converts without vomitting on unwanted characters?
    And by the way, I used to (about 1+ years ago) be able to look at a reference online that gave a detailed description of the Java standard class methods. Know where I might find this?
    -erik

    you can refer the api at
    http://java.sun.com/j2se/1.3/docs/api/

  • UTF8 double conversion

    This question was answered in other thread.

    Windows 1251 is, unfortunately, the requirement for PDO_ODBC. While I have not found any PHP documentation stating this, I am pretty sure that PDO_ODBC uses ODBC in the ANSI mode. Oracle ODBC driver is a Unicode (UTF-16) driver and the translation between ANSI and Unicode is done by the Windows ODBC Driver Manager. This conversion is always between the system ANSI code page (1251 in your case) and UTF-16. You cannot configure PDO_ODBC to accept strings in UTF-8 as the system ANSI code page cannot be UTF-8.
    You can try UTF-8 only with the PDO_OCI.
    -- Sergiusz

  • Bug report:on application import: page template substitution strings double

    apex version: 4.2.0.00.27
    We encounter an issue when we import an application export. In all the page templates we see that the standard substitution strings in the HEADER and FOOTER area have been added for a second time.
    EXPORTED CODE:
    wwv_flow_api.create_template (
    p_id => 32176400365879390 + wwv_flow_api.g_id_offset
    ,p_flow_id => wwv_flow.g_flow_id
    ,p_theme_id => 20
    ,p_name => '_vo_One Level Tabs_Simple'
    ,p_is_popup => false
    ,p_header_template => '<html lang="&BROWSER_LANGUAGE." xmlns:htmldb="http://htmldb.oracle.com">'||unistr('\000a')||
    '<head>'||unistr('\000a')||
    '<title>#TITLE#</title>'||unistr('\000a')||
    '<script type="text/javascript" src="#IMAGE_PREFIX#app/common/js/app_common2.js"></script>'||unistr('\000a')||
    '<script type="text/javascript" src="#IMAGE_PREFIX#app/common/js/datepicker.js"></script>'||unistr('\000a')||
    '<script type="text/javascript" src="#IMAGE_PREFIX#app/common/js/datepicker-ext.js"></script>'||unistr('\000a')||
    '<script type="text/javascript" src="#IMAGE_PREFIX#app/common/js/app_show_hide_region.js"></script>'||unistr('\000a')||
    '<script type="text/javascript" src="#IMAGE_PREFIX#app/common/js/app_desktop_all.js"></script>'||unistr('\000a')||
    '<script type="text/javascript" src="#IMAGE_PREFIX#app/common/js/app_legacy.js"></script>'||unistr('\000a')||
    '<link rel="stylesheet" href="#IMAGE_PREFIX#app/pbh/css/pbh.css" type="text/css" />'||unistr('\000a')||
    '<!--[if IE]><link rel="stylesheet" href="#IMAGE_PREFIX#themes/theme_20/ie.css" type="text/css" /><![endif]-->'||unistr('\000a')||
    '#APEX_CSS#'||unistr('\000a')||
    '#TEMPLATE_CSS#'||unistr('\000a')||
    '#THEME_CSS#'||unistr('\000a')||
    '#PAGE_CSS#'||unistr('\000a')||
    '#TEMPLATE_JAVASCRIPT#'||unistr('\000a')||
    '#APPLICATION_JAVASCRIPT#'||unistr('\000a')||
    '#PAGE_JAVASCRIPT#'||unistr('\000a')||
    '#HEAD#'||unistr('\000a')||
    '</head>'||unistr('\000a')||
    '<body #ONLOAD#>#FORM_OPEN#'
    ,p_box =>
    '<div id="t20Tabs">#TAB_CELLS##NAVIGATION_BAR#</div>'||unistr('\000a')||
    '<table border="0" cellpadding="0" cellspacing="0" summary="" id="t20PageBody" width="100%">'||unistr('\000a')||
    '<td width="100%" valign="top" id="t20ContentBody">'||unistr('\000a')||
    '<div id="t20BreadCrumbsLeft">#REGION_POSITION_01#</div>'||unistr('\000a')||
    '<div id="t20Messages">#GLOBAL_NOTIFICATION##SUCCESS_MESSAGE##NOTIFICATION_MESSAGE##REGION_POSITION_02#</div>'||unistr('\000a')||
    '<div id="t20ContentMiddle">#BOX_BODY##R'||
    'EGION_POSITION_03##REGION_POSITION_04##REGION_POSITION_05##REGION_POSITION_06#</div>'||unistr('\000a')||
    '</td>'||unistr('\000a')||
    '</tr>'||unistr('\000a')||
    '</table>'
    ,p_footer_template =>
    '<div class="smallfont">PBH Versie: #APP_VERSION#</div>'||unistr('\000a')||
    '#FORM_CLOSE# '||unistr('\000a')||
    '#DEVELOPER_TOOLBAR#'||unistr('\000a')||
    '#GENERATED_CSS#'||unistr('\000a')||
    '#GENERATED_JAVASCRIPT#'||unistr('\000a')||
    '</body>'||unistr('\000a')||
    '</html>'
    ,p_success_message => '<table summary="" border="0" cellpadding="0" cellspacing="0" id="t20Notification">'||unistr('\000a')||
    '<tr><td class="L"></td><td width="100%">#SUCCESS_MESSAGE#</td><td class="R"></td></tr>'||unistr('\000a')||
    '</table>'
    ,p_current_tab => '#TAB_LABEL#'
    ,p_non_current_tab => '#TAB_LABEL#'
    ,p_notification_message => '<table summary="" border="0" cellpadding="0" cellspacing="0" id="t20Notification">'||unistr('\000a')||
    '<tr><td class="L"></td><td width="100%">#MESSAGE#</td><td class="R"></td></tr>'||unistr('\000a')||
    '</table>'
    ,p_navigation_bar => '#BAR_BODY#'
    ,p_navbar_entry => '#TEXT#'
    ,p_region_table_cattributes => ' summary="" cellpadding="0" border="0" cellspacing="5" align="left"'
    ,p_breadcrumb_def_reg_pos => 'REGION_POSITION_01'
    ,p_theme_class_id => 1
    ,p_grid_type => 'TABLE'
    ,p_grid_always_use_max_columns => false
    ,p_grid_has_column_span => true
    ,p_grid_emit_empty_leading_cols => true
    ,p_grid_emit_empty_trail_cols => false
    ,p_has_edit_links => true
    ,p_translate_this_template => 'N'
    ,p_template_comment => ''
    RESULT IN APEX for the HEADER
    <html lang="&BROWSER_LANGUAGE." xmlns:htmldb="http://htmldb.oracle.com">
    <head>
    <title>#TITLE#</title>
    <script type="text/javascript" src="#IMAGE_PREFIX#app/common/js/app_common2.js"></script>
    <script type="text/javascript" src="#IMAGE_PREFIX#app/common/js/datepicker.js"></script>
    <script type="text/javascript" src="#IMAGE_PREFIX#app/common/js/datepicker-ext.js"></script>
    <script type="text/javascript" src="#IMAGE_PREFIX#app/common/js/app_show_hide_region.js"></script>
    <script type="text/javascript" src="#IMAGE_PREFIX#app/common/js/app_desktop_all.js"></script>
    <script type="text/javascript" src="#IMAGE_PREFIX#app/common/js/app_legacy.js"></script>
    <link rel="stylesheet" href="#IMAGE_PREFIX#app/pbh/css/pbh.css" type="text/css" />
    <!--[if IE]><link rel="stylesheet" href="#IMAGE_PREFIX#themes/theme_20/ie.css" type="text/css" /><![endif]-->
    #APEX_CSS#
    #TEMPLATE_CSS#
    #THEME_CSS#
    #PAGE_CSS#
    #TEMPLATE_JAVASCRIPT#
    #APPLICATION_JAVASCRIPT#
    #PAGE_JAVASCRIPT#
    *#APEXCSS#*_
    *#TEMPLATECSS#*_
    *#THEMECSS#*_
    *#PAGECSS#*_
    *#APEXJAVASCRIPT#*_
    *#TEMPLATEJAVASCRIPT#*_
    *#APPLICATIONJAVASCRIPT#*_
    #HEAD#
    </head>
    <body #ONLOAD#>#FORM_OPEN#
    The added substitution strings are bold + underlined.
    Is there a parameter (application, export, template, instance level) that we can set to prevent this ?
    Edited by: Karel C on 12-feb-2013 5:32
    Edited by: Karel C on 12-feb-2013 5:32

    Hi Patrick,
    The version info is: wwv_flow_api.set_version(p_version_yyyy_mm_dd=>'2009.01.12');
    This should be wwv_flow_api.set_version(p_version_yyyy_mm_dd=>'2012.01.01');
    ... but this error is due to a manual modification of the export file.
    We parameterise some values, so that the we can use the old-school DEFINE variables in our deploy process via SQL/plus.
    One of the developers made a copy-paste error when doing that ...
    So there is no bug !
    Thanks for the tip !!
    Kind regards,
    Karel

  • JDBC string- number conversion in Canadian locale

    How come Oracle JDBC driver thinks "2.1" is an invalid number in Canadian locale? The decimal point in Canadian locale is still "." as used in US locale. It is easy to verify this by changing your locale to English (Canada) and check the "Number" settings on your Windows machine.
    This is definitely a bug. Can antone from Oracle confirm this?
    Thanks.

    It is working now because you have imported oracle.jbo.domain.Number and hence not using java.lang.Number.
    java.lang.Number is a abstract class and hence no constructors, whereas oracle.jbo.domain.Number has many constructors (one of which Srinath suggested to use.)
    you can still make it work with
    oracle.jbo.domain.Number n = new oracle.jbo.domain.Number(businessReqID) ; //if businessReqID is a String.
    You dont need to get the int from the String in order to use this constructor.
    Thanks
    Tapash

  • String character conversion

    Can anyone explain me why there are 5 characters in the first range of 256 that are coded back to the question mark.
    for (int i = 0; i < 256; i ++)
         byte[] bytes = new byte[1];
         bytes[0] = (byte) i;
         String temp = new String(bytes);
         byte[] result = temp.getBytes();
         if (result[0] != bytes[0])
              System.out.println(i + ") byte->" + bytes[0] + "< result->" + result[0] + "<");
    }characters 129 (reserved), 141 (RI), 143 (SS3), 144 (DCS) and 157 (OSC) are changed. I m using JDK 1.4.2_02.
    I'm posting it here because I stumbled on it when I was trying to convert a string (known to me as UTF-8) to a Java UTF-8 String. The Greek lower RHO character is '0xCF 0x81' and that last one is 129.

    Rather than crossing your fingers and hoping for the right encoding, you should provide the encoding you wish to transcode explicitly. Here, I test US-ASCII and ISO-8859-1. US-ASCII complains for all code points above 127 (as expected; it's a 7-bit encoding), whereas ISO-8859-1 runs without complaining.
    public class TestEncoding {
      public static void main(String[] args) throws Exception {
        String[] encodings = new String[] {
          "US-ASCII", "ISO-8859-1"
        for (int i = 0; i < encodings.length; i++) {
          System.out.println("TESTING ENCODING: " + encodings);
    testEncoding(encodings[i]);
    public static void testEncoding(String encodingName) throws Exception {
    for (int i = 0; i < 256; i ++) {
    byte[] bytes = new byte[1];
    bytes[0] = (byte) i;
    String temp = new String(bytes, encodingName);
    byte[] result = temp.getBytes(encodingName);
    if (result[0] != bytes[0]) {
    System.out.println(i + ") byte->" + bytes[0] + "< result->" + result[0] + "<");

  • IMessage double conversations

    Me and my girlfriend both have iPhone 4s and iMac. When i send an iMessage/SMS they create two different conversations. IMessages that send to my girlfriend's e-mail come from my phone number and vice versa. So we have two indepdent conversations and that's bad. And now Mac OS X iMessage beta appears. And when i send message from my imac she recive it only on iphone. When she sends message from iphone i recieved it both on imac and phone.

    HI,
    Actually there is not. (well not that easy anyways)
    Message beta should be saving All Chats in the iChats folder.
    By default this is in your Home Folder/Documents.
    Check the iChats Folder has the chats that you want to delete (It is also no good deleting them here as these are not the bits that are called back)
    Once you know they are saved then  you need to do the Following.
    In the Finder > Go Menu hold the ALT key down to seethe Library item
    Select this
    Open the Messages folder
    The Sub folder called Attacthments is the chats that had Pic or Files in them.
    The three Chat.db and Chat.db-xxx iterms are the files involved in bringing back those Chats.
    IF you use Quick Look to open them you may be prompted that TextEdit can open them.  (You may want to do this as a further check)
    The Chat.db one can then be either edited or deleted (it will get recreated).
    7:44 PM      Wednesday; May 9, 2012
    Please, if posting Logs, do not post any Log info after the line "Binary Images for iChat"
      iMac 2.5Ghz 5i 2011 (Lion 10.7.3)
     G4/1GhzDual MDD (Leopard 10.5.8)
     MacBookPro 2Gb (Snow Leopard 10.6.8)
     Mac OS X (10.6.8),
    "Limit the Logs to the Bits above Binary Images."  No, Seriously

  • How to convert a string into double?

    Hi. I'm having a string with 10340.8878 which is essentially a GPS latitude coordinate. I will need to break it up separately into double type 103,40 and 88.
    103 refers to the degree
    40 refers to the minutes
    88 refers to the seconds
    I will also need to perform a double conversion: the second separated double(40) divided by a factor of 60 and the third separated double(88) divided by a factor of 360.
    How can i go about doing this?
    Thanks!

    new Double(str).doubleValue();
    http://java.sun.com/j2se/1.4.1/docs/api/java/lang/Double.html

Maybe you are looking for