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

Similar Messages

  • 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                                                                                                                                                                                                                                                                               

  • I have proubleam with string to date conversion, i out put date fromat is 2012-04-30T23:48:55.727-07:00 . so please help me the format conversion

    i have proubleam with string to date conversion, i out put date fromat is 2012-04-30T23:48:55.727-07:00 . so please help me the format conversion.
    i wrote the method but it not workig
    My method is
    -(NSDate *)dateformstr:(NSString *)str
    NSString *date = [str stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
        NSDateFormatter *dateFormate = [[NSDateFormatter alloc] init];
      [dateFormate setDateFormat:@"yyyy-MM-dd'T'HH:mm:sssZZZZ"]
    // NSDate *formatterDate = [dateFormate  dateFromString:str];
        return formatterDate;
    but i did not the value and if i try othere formate i is working but my requiremet format is 2012-04-30T23:48:55.727-07:00.
    can any help it out in this senario.

    Sorry Butterbean, but I'm interested in the answer to your question myself.
    I've spent a few hours transfering my library from one computer to another and then find out that my ratings didn't transfer. Like you, I've spent many hours rating my 2000+ songs. I'm sure you have more, nevertheless, I want to find out how to get those ratings. They still show in my iTunes on my laptop but, when I go to the iTunes folder and display the details of at song, no rating is there. If you find out how to get them to display there in the iTunes folder, it seems that would be the key.
    Hope you get your answer soon.

  • Kinda urgent    please help pass strings to doubles and strings to ints

    Need to know how to pass strings to doubles and strings to ints
    and to check if a string is null its just if (name == null;) which means black right?
    like size as a string and then make the string size a double

    cupofjava666 wrote:
    Need to know how to pass strings to doubles and strings to ints
    and to check if a string is null its just if (name == null;) which means black right?
    like size as a string and then make the string size a doubleThink he means blank.
    Check the Wrapper classes (Double, Integer) in the api.
    parseInt() parseDouble() both take a string and return a primitive.
    String s = null;
    if(s == null) should do the trick!
    Regards.
    Edited by: Boeing-737 on May 29, 2008 11:08 AM

  • Help needed (converting string to double)

    keep getting an error someone give me a hint
    public class q1d
        public static void main(String [] args)
            String whats;
            double x;
            x = (String)whats;
            System.out.println(+x);
    }

    Then study this tutorial
    http://java.sun.com/docs/books/tutorial/
    Specifically, this part
    http://java.sun.com/docs/books/tutorial/java/data/index.html
    You need some basic knowledge. These forums are not suitable for teaching Java. The tutorial is.

  • Splitting CSV file; output a simple tokenised string of doubles - HELP

    Okay here it goes? I have a file that contains comma delimited double values in the form;
    2,3
    2.8,9.0
    4.8,9.0
    I am trying to get the values in to the a simple string of "2 3 2.8 9.0 4.8 9.0". Therefore i have tried to replace all commas with a space and then split on whitespace? no success there?
    Th other way is to split on white space string.split("\\s+") and creat a string [] array and then loop through each element of the array creating a multi dimensional array of seperated values. These i could then concatente to form a string?
    My question is where is my code going wrong for spliting the string???
    package LineGraph;
    import java.util.*;
    import java.io.*;
    public class ReadData extends Thread {
         private Cdf cdf = null;
         private String fileName = null;
         String rawData = "";
         double[][] data = creatData();
         static double[][] creatData() {
              String rawData = GUI.jta.getText();
                System.out.println("rawData: " + rawData);
                String dataSet = rawData.replaceAll(",","\\s+"); 
                String [] point = null;
                point = rawData.split("\\s+");
                for (int i=0; i < point.length; i++){
                     System.out.println("point:" + point);
              //for (int i = 0; i < dataSet.length; i++){
              //System.out.println("dataSet: " + dataSet[i]);
              //String [] point = null;
              //if (dataSet.length > 0) {
              // point = dataSet[0]; // start with the first element
              // for (int i=1; i<dataSet.length; i++) {
              // point = dataSet[i];
              //System.out.println("point:" + point);
              //String[] CoOrd = point.split(",");
              String result = "";
              if (point.length > 0) {
                   result = point[0];
                   for (int j=1; j<point.length; j++) {
                        result = point[j];
              StringTokenizer tokens = new StringTokenizer(result);
              List list = new LinkedList();
              while (tokens.hasMoreElements()){
                   String number = "";
                   String token = tokens.nextToken();
                   for (int i=0; i<token.length(); i++){
                        if (Character.isDefined(token.charAt(i))){
                             number += token.substring(i, i+1);
              if (!number.equalsIgnoreCase("")){
                   boolean add = list.add(number);
         System.out.println("list:" + list);
              double [][]data = new double[list.size()/2][2];
              int index = -2;
              for (int i=0; i<data.length;i++){
                        index += 2;
                        data[i][0] = Double.parseDouble(
                                  (list.get(index).toString()));
                        data[i][1] = Double.parseDouble(
                                  (list.get(index +1).toString()));
              System.out.println("data.length: " + data.length); //** add this -- see how much data is being created
              return data;
              //cdf = new Cdf(data, fileName, PrintMessage);
         public Cdf getCdf(){
              return this.cdf;

    the point being there are 2 delimiters to split, the first being the comma the second being the line break thus creating an array of single digits
    I have solved the issue by using replaceall to replace all commas with spaces and then split on the spaceStill makes no sense. A line break doesn't not contain spaces. So how does replacing commas with spaces allow you to split on the line break.
    If you are appending each line to a string (to build one long string) then append the data with a comma, not a space.
    I really get the idea you guys are not enjoying my code?Its your requirements we don't understand. You obviously aren't explaining them correctly.

  • Need Help with data type conversion

    Hello People,
    I am new to java, i need some help with data type conversion:
    I have variable(string) storing IP Address
    IPAddr="10.10.103.10"
    I have to call a library function which passes IP Address and does something and returns me a value.
    The problem I have is that external function call in this library excepts IP Address in form of a byte array.
    Here is the syntax for the function I am calling through my program
    int createDevice (byte[] ipAddress).
    now my problem is I don't know how to convert the string  IPAddr variable into a byte[] ipAddress to pass it through method.

    Class InetAddress has a method
    byte[]      getAddress() You can create an instance using the static method getByName() providing the IP address string as argument.

  • 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

  • Convert String to double with two digits

    How can I format "String" type of numbers (eg. 199.0, or 199) to return a "double" type of nubmers like 199.00, or 199.00. It should have two digits.
    For example, the input is String of 199.0, how can I get "double" 199.00. Always format as two digits.
    Thanks for your help,

    Thanks for replying.
    Here is my code. For some reason, when convert the returned String back to double in main, it cut the "0".
    What's wrong with my code? How can I get that 4.60 in double type.
    Thanks again,
    ==================================================================================
    import java.text.*;
    import java.util.*;
    import java.sql.*;
    public class NumUtils
    // Convert Double to 99.99
    public static String format(String str)
    //double d = 4.6;
    double d = Double.parseDouble(str);
    NumberFormat formatter = new DecimalFormat("0.00");
    formatter.setMaximumFractionDigits(2);
    String s = formatter.format(d);
    return s;
    public static void main(String[] args)
    String myDouble = "4.6";
    String mynewdouble = format(myDouble);
    System.out.println(" --- formatDouble = " + mynewdouble);
    double my_d = Double.parseDouble(mynewdouble);
    System.out.println(" --- Double = " + my_d);

  • Problem with String to Int conversion

    Dear Friends,
    Problem with String to Int conversion
    I am having a column where most of the values are numeric. Only 4 values are non numeric.
    I have replaces those non numeric values to numeric in order to maintain the data type.
    CASE Grade.Grade  WHEN 'E4' THEN '24'  WHEN 'E3' THEN '23'  WHEN 'E2' THEN '22' WHEN 'E1' THEN '21' ELSE Grade.Grade  END
    This comes the result as down
    Grade
    _0_
    _1_
    _10_
    _11_
    _12_
    _13_
    _14_
    _15_
    _16_
    _17_
    _18_
    _19_
    _2_
    _20_
    _21_
    _22_
    _23_
    _24_
    _3_
    _4_
    _5_
    _6_
    _7_
    _8_
    _9_
    Refresh
    Now I want to convert this value to numeric and do some calculation
    So I changed the formula as below
    cast (CASE Grade.Grade  WHEN 'E4' THEN '24'  WHEN 'E3' THEN '23'  WHEN 'E2' THEN '22' WHEN 'E1' THEN '21' ELSE Grade.Grade  END as INT)
    Now I get the following error
    View Display Error
    _     Odbc driver returned an error (SQLExecDirectW)._
    Error Details
    Error Codes: OPR4ONWY:U9IM8TAC:OI2DL65P
    _State: HY000. Code: 10058. [NQODBC] [SQL_STATE: HY000] [nQSError: 10058] A general error has occurred. [nQSError: 17001] Oracle Error code: 1722, message: ORA-01722: invalid number at OCI call OCIStmtFetch. [nQSError: 17012] Bulk fetch failed. (HY000)_
    SQL Issued: SELECT cast ( CASE Grade.Grade WHEN 'E4' THEN '24' WHEN 'E3' THEN '23' WHEN 'E2' THEN '22' WHEN 'E1' THEN '21' ELSE Grade.Grade END as Int) saw0 FROM "Human Capital - Manpower Costing" WHERE LENGTH(CASE Grade.Grade WHEN 'E1' THEN '20' WHEN 'E2' THEN '21' WHEN 'E3' THEN '22' WHEN 'E4' THEN '23' ELSE Grade.Grade END) > 0 ORDER BY saw_0_
    Refresh
    Could anybody help me
    Regards
    Mustafa
    Edited by: Musnet on Jun 29, 2010 5:42 AM
    Edited by: Musnet on Jun 29, 2010 6:48 AM

    Dear Kart,
    This give me another hint, Yes you are right. There was one row which returns neither blank nor any value.
    I have done the code like following and it works fine
    Thanks again for your support
    Regards
    Code: cast (CASE (CASE WHEN Length(Grade.Grade)=0 THEN '--' ELSE Grade.Grade END) WHEN 'E4' THEN '24' WHEN 'E3' THEN '23' WHEN 'E2' THEN '22' WHEN 'E1' THEN '21' when '--' then '-1' ELSE Grade.Grade END as Int)

  • Strange outputs while parsing String to Double

    Hi All,
    I am writing a simple MIDlet on MIDP 2.0 and CLDC 1.1, where I need to convert two strings into Double calculate their difference and then display the result back on the screen.
    The code I am using is:
        double difference = Double.parseDouble("1235.7") - Double.parseDouble("1234.5");
        String result = (String)Double.toString(difference); The output generated is : 1.2000000000000455 which should be only 1.2
    If I replace the values with "1235" and "1234.1" the output is 0.900000000000091 which should be 0.9
    However, if I change the values to "1235.6" and "1234.1" the output generated is 1.5 which is perfectly fine. Means this happens only for some specific set of values.
    Has anyone ever faced such a situation or if anyone knows a proper workaround to fix this please help me out.
    Thanks.

    Is this normal? does this also happens in case of J2SE I have never tried a similar
    program on j2se.If you are talking about the innaccuracies in the calculations then yes. Look at the url I gave in my previous post, some guy was asking the same thing and it wasn't about J2ME.
    In fact, this happens in every other language as well. It a limitation of the format doubles are stored in.
    shmoove

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

  • StringTokenizer class problem with strings in double quotes

    Hello Technocrats,
    I have a problem with tokenizing following string enclosed in (). (abc," India, Asia", computer engineer). My separator is ",", thus StringTokenizer class gives me 4 tokens namely abc, "India, Asia" and computer engineer. But I require that String in double quotes should be a single token. How to achieve this using StringTokenizer class? Or is there any other way?
    Thanks in advance.

    Try
    String[] str="abc,\" India, Asia\",computer engineer".split(",",1);
              for(String s: str)
                   System.out.println(s);
              }Thanks.

  • Missing charsets in STring to FontSet conversion

    Hi,
    After installed SUn OS 10, I am trying to install SMC and I got a warning error: Missing Charsets in String to FontSet conversion. Cannot convert string "-monotype_arrial-regular-r-normal --*-140-*-*-p-*-iso8859-2" to type FonsStruct
    and so on, with different font types. etc....
    How can I find out which fontset in the Unix box? How can I permanent set it back to UTF-8 w/o re install OS again?
    Thanks
    HS

    Too bad Lily didn't follow up on TommyReynolds' suggestion. I'm also having the same problem ( I think ).
    TommyReynolds does say how to get the installed list, but doesn't say how to find out what's missing.
    My settings:
    [root@OEL5u4DB11gR2 X11]# rpm -qa 'xorg*font*' | /bin/sort
    xorg-x11-fonts-100dpi-7.1-2.1.el5
    xorg-x11-fonts-75dpi-7.1-2.1.el5
    xorg-x11-fonts-base-7.1-2.1.el5
    xorg-x11-fonts-ISO8859-1-100dpi-7.1-2.1.el5
    xorg-x11-fonts-ISO8859-1-75dpi-7.1-2.1.el5
    xorg-x11-fonts-misc-7.1-2.1.el5
    xorg-x11-fonts-truetype-7.1-2.1.el5
    xorg-x11-fonts-Type1-7.1-2.1.el5
    xorg-x11-font-utils-7.1-2
    [root@OEL5u4DB11gR2 X11]# uname -a
    Linux OEL5u4DB11gR2 2.6.18-164.el5 #1 SMP Thu Sep 3 02:16:47 EDT 2009 i686 i686 i386 GNU/Linux
    [root@OEL5u4DB11gR2 X11]# xclock &
    [1] 5950
    [root@OEL5u4DB11gR2 X11]# Warning: Missing charsets in String to FontSet conversion
    I would greatly appreciate any input.
    Kind regards,
    UFP1701

Maybe you are looking for

  • How to use .dbf files zipped into a .zip file from within a java program

    i have a .zip file containing several .dbf files. the zip file is automatically downloaded regularly and data from the .dbf files is inserted into the database. how do i facilitate automatic extraction of a zip file or how do i fetch data from the .d

  • Parsing data from a BLOB

    I am relatively new to oracle, however I've been working with other databases for years. I would like to load a csv file into a blob record and then parse that record to populate a separate table. Ideally I would use Applications Express to allow a u

  • Jpub invalid column name error

    I try to create a Wrapper for a PL/SQL Package in a Oracle8i database with jpublisher. I created Packages and Object Types with the SQl script Rational.sql. \oracle\ora81\sqlj\demo\jpub\Rational.sql jpub failed to produce any sqlj or java files, but

  • Human Tasks in BPEL

    I have a workflow that needs to include a human review point for quality control purposes. I have added a "Human Task" at that point, and that seems to partially work. I can see the tasks in BPM and I can Approve the task. What's not working is that

  • 'cc' is not available

    Hi, Am a newbie for this Oracle E-business suite, and i have been searching lot of links for installing and found this thread which has been very very informative and thanks a lot for the post. I have downloaded the oracle 11i suite from e-delivery a