How do I convert a String to double~?

The contents of a file named data.txt are shown below:
1.2402 .7930 .3254 -.0994 -.2930 -.4233 -.4539 -.1423
-.0007 -.3118 -.6208 -.9524 -1.3694 -1.3870 -.9214 -.3621
.1633 .9746 2.0815 2.5352 1.8879 1.0037 .3276 -.2085
I want to read these data from data.txt.
Below are the code I use to read file:
//read file
BufferedReader br = new BufferedReader(objFileReader);
//lstrLine contains one line data,
String strLine = br.readLine();
Question:How can I convert String strLine to double [ ] dbLine ?
For example,convert String strLine=" 1.2402 .7930 .3254 -.0994 -.2930 -.4233 -.4539 -.1423" to dbLine[0]=1.2402,dbLine[1]=.7930,dbLine[2]=.3254,dbLine[3]=-.0994,dbLine[4]=-.2930,dbLine[5]=-.4233,dbLine[6]=-.4539,dbLine[7]=-.1423

String.split(), DecimalFormat

Similar Messages

  • How do I convert a string, and use a string as a property?

    I have an array in the following format:
    {ownsCar: 'true', ownsBike: 'true', ownsHouse: 'true'}
    {ownsCar: 'false', ownsBike: 'true', ownsHouse: 'true'}
    {ownsCar: 'true', ownsBike: 'false', ownsHouse: 'true'}
    etc ............
    And I need to test against each item e.g.
    if...
    myDataGrid[myItem].ownsCar == Object(myCheckbox).label
    ... then
    if...
    myDataGrid[myItem].ownsBike == Object(myCheckbox).label
    ... then
    if...
    myDataGrid[myItem].ownsHouse == Object(myCheckbox).label
    ... then
    But I need to build my application where the property (e.g. "ownsCar", "ownsBike", "ownsHouse") is a variable such as:
    if...
    myDataGrid[myItem].myProperty == Object(myCheckbox).label
    ... then
    I would like to loop through my Array, counting the number of items, and then use each item as a property.
    How would I convert the string (e.g. "ownsCar") into a property "myProperty" ???
    Many thanks in advance
    Chris

    Thanks, but my problem is that I won't know what my property will be.
    E.g. they could be...
    {svnsdkvnsdklvnsdklv: 'true', seuAfnwfnw: 'true', asfwseionf: 'true', etc.................}
    and there could be lots of them.
    I need to have myObject[N], where N is a variable property for each of the items taken from a variable length array
    so...
    ownsCar is represented by myObject.[N]
    ownsHouse is represented by myObject.[N+1]
    ownsBike is represented by myObject.[N+2]
    etc
    (sorry, this is so difficult to explain when I dont know what the answer is)

  • How can I convert a string to a seperated characters?

    How can I convert a string to a separated characters without using array?
    such as: input = String "word"
    output =
    w
    o
    r
    d
    Thanks

    A string is stored internally in individual characters.
    The String class has a method 'charAt(int index)' which returns the character at that index so using a for loop..
    String s = "word";
    for(int counter=0; counter < s.length(); counter++)
    System.out.println(s.charAt(counter));
    HTH

  • How do you convert this String into a double?

    Hi, in this code I want to convert String arg into a double. I'm trying to do this so that I can convert some string into a double in this calculator that I'm making. Here is the code:
    public class par {
    public static void main(String[] args) {
    String str = "351";
    double arg = new double(str); // should convert the string into a double
         System.out.println(arg);
         System.out.println(str);
    I keep getting errors in line 4, if any of you could help me out here I'll be thankful, i'm kinda new to java and my search for java's equivalent of alof() (its a function in C libraries that converts char[] into a double)lead me to this.
    Tony L.

    Use the Following:
    String num = "123.2";
    double d = Double.parseDouble(num);

  • How do I convert a string to a double, a number loses the precision

    I tried converting a string to a double but that limits the precision. I need to convert a string to a double.

    If you use the Scan From String function, the default is to convert to a dbl. If you're looking at a front panel indicator, don't confuse the format and precision of the indicator with the type representation. You can set the indicator to display as many digits as you want but that doesn't change the actal number stored in memory.

  • How do I convert a string into a decimal

    I've been tryin to convert a string into decimal but I can't get it to work at all. I keep getting an exception.
    I've tried all of these:
    double myDouble = Double.valueOf(string).doubleValue();
    int myint = Interger.parseInt(string);
    float myfloat = Float.parseFloat(string);
    I can't get anything to work.
    That string i'm reading in is an array containing values with decimals. ex: -45.09348
    All the above work fine if there is no decimal, but fails when it comes to one.
    How do I go about doing this?
    Thanks!

    This works for me:String s = "-45.6789";
    double d = Double.parseDouble(s);
    System.out.println(d);Mark

  • How can I convert a String into an int?

    I need to use command-line args. So I enter "java Main 123" and I want to use 123 not as a String but as an int.
    How can I convert it into an int?
    Thank You!!
    Sprocket

    Example method (you don't need to use a method unless you do this a lot)
    private int stringTOInt (String aString)
    int result = 0;
    try
    result = Integer.parseString(aString);
    catch (Exception ex)
    System.out.println ("Failed to convert string " + aString + " to int.");
    return result;
    }

  • Convert a string to double with precision

    I am getting a value amount of say $45.00 from a jsp and set this value as a string for my other work. then i am changing this string to double by using this statement
    setAmount(Double.parseDouble(cstmt.getString(1)));
    my precision is lost when i get this amount it just shows 45.0 how can I get the precision of 45.00
    I would appreciate if any assistance is provided for the problem.
    thanks

    JSP's can use NumberFormat.
    However you should never use float/double to represent monetary values. Money has an absolute value (in terms of units used to purchase). Float and double do not (actually they do but they are in base 2 NOT base 10 like most money is). In most cases representation errors due to float and double do not really matter (if you have suitably analysed the usage of them) however people get very upset about errors when it comes to money
    matfud.

  • How do I convert a String to a DateTime in SQL ??

    I have retreived the current date and time and place into String data type. but my table colmun is in datetime data type.
    How do I convert ??
    Thanks in advance.

    I have retreived the current date and time and place
    into String data type. but my table colmun is in
    datetime data type.
    take a look at the SimpleDateFormat class...
    http://java.sun.com/j2se/1.3/docs/api/java/text/SimpleDateFormat.html
    basically something like this...
    SimpleDateFormat sdf = new SimpleDateFormat();
    java.util.Date dt = sdf.parse(dateAsString);
    java.sql.Timestamp ts= new java.sql.Timestamp(dt.getTime());anyway it can handle different formats and i believe you can create your own if you need to.
    ps this question would have been better posted in the JDBC forum.

  • How Do I Convert a String that Names an Object to a Reference to the Object

    You get many program-specific object names in the XML that is returned by describeType.  Suppose I find an object that interests me.  What is the best way to convert the String that names the object (e.g. the id of the object) to a reference variable that points to the object? 

    Sure.  I am working on a complex application that involves several ViewStacks, several Accordions, some checkboxes, some radio buttons, some text boxes.  These components are scattered about, but all are children of a base class that is successfully enumerated by
    var classInfo:XML = describeType(vwstk);
    Suppose I write a loop as follows:
     for each (var a:XML in classInfo..accessor){
    Inside that loop I have a series of tests like
    if (a.@type == "mx.controls::CheckBox"{
    Then, I iterate thru all of the children of the base class as in:
    for  
    (var u:Object in vwstk)
    {        if  
    Inside the if I persist the checked/not checked status of the checkbox.
    The tricky part is going from the string a.@name to the Object reference u.  I doubt my proposed method will work.  Do you have a better idea?

  • How can I convert a string of hex values to a hex format string programatically?

    Is there a way to convert a string of the following format:
    1400010107070D0305006A01 ........           ("Normal display" string)
    programatically to:
    1400 0101 0707 0D03 05006A01 ..........      ("Hex display" striing)
    I need to do this in order to calculate a CRC16 value.
    See attached VIs
    Thank you.
    Solved!
    Go to Solution.
    Attachments:
    CMM_SN_MULTI.vi ‏50 KB
    CMM_CRC16_Calculator.vi ‏23 KB

    You can iterate over the string and use the String to Hex VI. If you work with two bytes of the string at a time you can get a U8 array of the desired binary values. Then when you are complete you can either work with the byte array of convert it back to a string using Byte Array to String.
    EDIT: GerdW typed faster than I did.
    Message Edited by Mark Yedinak on 03-18-2010 02:55 PM
    Mark Yedinak
    "Does anyone know where the love of God goes when the waves turn the minutes to hours?"
    Wreck of the Edmund Fitzgerald - Gordon Lightfoot

  • How can I convert a string into an image

    I want to convert a string into an image.
    I want to know required steps for that.

    look at http://forum.java.sun.com/thread.jsp?forum=31&thread=194763
    drawString looks as something you might need

  • 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

  • Converting from string to double (formula)

    Hi All,
    I have a formula stored in properties file (i am doing some android dev) and retrieveing that formula using following stmt
    double c = 35.0;
    String res = this.getResources().getText(R.string.celsiusfahrenheit).toString();
    The returned value of string res is (1.8*c)+32
    How do i make the above stmt to substitue value of c into above equation and returned me the result value.
    thx
    vinod

    vinod_kmr wrote:
    Hi All,
    I have a formula stored in properties file (i am doing some android dev) and retrieveing that formula using following stmt
    double c = 35.0;
    String res = this.getResources().getText(R.string.celsiusfahrenheit).toString();
    The returned value of string res is (1.8*c)+32
    How do i make the above stmt to substitue value of c into above equation and returned me the result value.
    thx
    vinodas I understand you actually want to solve. if so, and res always returns that formula, then you can skip the properties file and just solve it already. something like:
    double result = (1.8*c) + 32.0if the result you are looking for is res with the value of the double substituted for c in the formula then the first step is to convert the the double c into a string and sticking that in res using String.replace(). something like
    res = res.replace("c", Double.toString(c));of course I don't know if String in android is like java.lang.String (same with Double) but I'm sure an equivalent exist.

  • How can I convert a string to an object or class

    I would like to read a file representing a class, and convert it to an object or a class (object preferred). Other postings suggest using javax.tools.JavaCompiler to convert from a string but then say that this is not always available (posting on 1 Jan 09). If this is still not universally available is there another way to do this? If this is not available, are there any examples of how it should be done?
    My understanding from what I've read is to read the file into a String then compile the String using javax.tools.JavaCompiler, which is an Interface.
    thanks

    skidmarks wrote:
    What i would like to do is to take a Java file representing a class and compile it at runtime. However, the comment about a JDK being available at runtime makes this unattractive.So, you want to compile .java files, but you don't want to have to use a compiler?
    The next guess would to be to create a .jar file and reference it at runtime. Here's the scenario:Eh? How is that even remotely equivalent?
    1. People using the 'system' will have a varied knowledge of Java.
    2. My hope was to require that anyone using the program would only need to create a Java Class file,You mean a Java source file. You have said that YOU want to create the .class file. If they are creating the .class file, then all you need to do is load it with a ClassLoader and start using it.
    You might try clarifying your requirements a bit.
    In either case, the Class Files would look like:
    public class Name {
    int field1;
    float field2;
    } With all the field types being simple Java Primitives.What is the point of this? What are you ultimately trying to accomplish, that can be served by user-defined groups of primitives, with no complex object graphs and no user-defined methods?
    Depending on what you're really getting at, using scripting features via beanshell, groovy, or javascript might be an approach to consider, or using Scala to produce a domain-specific language (although I suspect that last may be overkill, and beyond your current skill level).
    If this is so, is there any way to create a .jar file at runtime? Do I have to exec("jar") or is there another way.A .jar file is just a .zip file with a manifest. Look at the java.util.jar package. But note that creating a .jar file has nothing to do with the rest of what you're asking about.

Maybe you are looking for

  • Spend a lot of time to insert

    Hi, I have a Insert which spend a lot of time. Is a simple insert: INSERT INTO TFE002 (X_NOMCORRECTO,C_TITULAR,X_APPCORRECTO,X_ANOVAL, C_MODULAR,X_APMCORRECTO,C_USUARIO,C_POBLACION, C_FORMATO,C_LOTE,C_SECUENCIA,C_PERIODO, X_T,X_NI,X_GRADO,X_SEXO,X_LO

  • How to search contacts in the new version?

    What the heck Skype?! I have hundreds of contacts. Before I could simply go to my contacts and SEARCH! Now? Scroll forever? Also sometimes I have like "FULL NAME MOBILE / HOME", thats not displaying since it is too long... As I could search before I

  • Unable to update Elements 6 for Mac

    Am having problems updating my program.  Adobe updater in Elements 6 indicates that I need to update and download "Adobe Camera Raw 4.6"  Once I download the progran and try to install it, I get an installer message that says "The update is unable to

  • Timer not in saved file

    Hello alltogether, I'm a newbie in LabView and I guess for you this question wil be quite easy. I want to have a File which also includes the time from the timer. What is the problem ? As you see, in my lvm file I only get the pixel and the measureme

  • JDBC Oracle, libweblogicoci37.so

    Hi, when I do the java utils.dbping ORACLE... I get the following error: Starting Loading jDriver/Oracle ..... Error encountered: java.sql.SQLException: System.loadLibrary(weblogicoci37) threw java.lang.UnsatisfiedLinkError: /opt/weblogic6/wlserver6.