Converting string to float

I have a decimal string "122339994" which i am trying to convert to float using Float.parseFloat. This results in incorrect value of 1.22339992E8.
I thought for floats precsision comes into effect after decimal places.
public static void main(String[] args) {
String floatString = "122339994";
float floatNumber = Float.parseFloat(floatString);
System.out.println("Float is "+floatNumber+". Now double "+Double.valueOf(floatString));
}

See this API
[Java2SE Float|http://download-llnw.oracle.com/javase/6/docs/api/java/lang/Float.html#valueOf%28java.lang.String%29]
Note that trailing format specifiers, specifiers that determine the type of a floating-point literal (1.0f is a float value; 1.0d is a double value), do not influence the results of this method. In other words, the numerical value of the input string is converted directly to the target floating-point type. In general, the two-step sequence of conversions, string to double followed by double to float, is not equivalent to converting a string directly to float. For example, if first converted to an intermediate double and then to float, the string
"1.00000017881393421514957253748434595763683319091796875001d"
results in the float value 1.0000002f; if the string is converted directly to float, 1.0000001f results.
Its better to see the Java APIs first for any information, we will get almost all the information we need from APIs
Regards,
Venkatesh

Similar Messages

  • Convert string to floating-point

    Hi all,
    ..very basic question, but I tryed it for hours and only received short-dumps
    <b>How can I convert a string into a floating-point number?</b>
    Kind regards,
    Stefan

    hi
    try this
    to convert  string to float.
    data : a type f,
    s type string value '1.023'.
    a = s.
    write :/ a.
    to convert float to string.
    data : a type f value '1.023',
    s type string.
    s = a.
    write : s.

  • Problem in Converting string to float

    Hi,
    I am reading from textField and trying to convert that string value to float.
    Compiler is giving error cannot find symbol toFloat even though I have included java.lang in my program.
    Please help me with this one.
    Thanks.

    Use
    float f = Float.parseFloat(inputString); //where inputString is the string you want to parse

  • Converting string to float number

    Here's what I'm trying to do. The user types a number, such as 12.011, in an input box. I want to check to see if the number they typed is between two numbers, such as 12 and 12.1. Therefore, I want to convert the string in the input box to a float number, not an integer, so I can check to see if it's in the correct range. How do I convert a string into a float number?
    thanks
    Mark

    Did you try:
    Number(textinput1.text);
    if(Number(textinput1.text)>12 && Number(textinput1.text)<12.1)

  • Convert string to float

    It seems extremely rudimentary but I haven't been able to find an answer yet.
    I would like to pass in a string representing a human-readable floating point (ie, non IEEE 754) and get its value.
    A straight up assignment of a string variable into a f variable doesn't work for thousand dividers. We would also need it for every scenarios:
    123.456
    123,456
    123456
    123456,789
    123.456,789
    123,456.789
    all should be valid inputs and the resolution should be dependent on system setting for number formats.
    I would like a built-in ABAP call with no manual processing. I'm sure this problem has been encountered thousands of times and solved thousands of times. No point reinventing the wheel.

    Tested Code
    Output as below
    String : 123,456,789,123.456
    String : 123456789123.456
    Float  :   1.2345678912345599E+11
    DATA v_str TYPE STRING VALUE '123,456,789,123.456'.
    DATA v_flt TYPE F.
    WRITE: / 'String :', v_str. "With Commas
    REPLACE ALL OCCURRENCES OF ',' IN v_str WITH ''.
    WRITE: / 'String :', v_str. "Without Commas
    CATCH SYSTEM-EXCEPTIONS ARITHMETIC_ERRORS = 1
                            CONVERSION_ERRORS = 2.
      MOVE v_str TO v_flt.
    ENDCATCH.
    WRITE: / 'Float  :', v_flt. "Float value

  • Convert from String to float

    How do I convert from String to float?

    Hi,
    you can use a Double for example - assuming value is that string to parse
    float f;
    try { Double d = new Double(value); f = d.floatValue(); }
    catch (NumberFormatException e) { f = 0.0; } // error - string value could not be parsed
    // here use your float fHope, that helps
    greetings Marsian
    P.S.: the Double class is usefull for that, because you also can get intValue(), doubleValue() or longValue() out of it for example. The StreamTokenizer for example parses numbers also only to double.

  • Converting strings to the floating number and plotting

    Hello,
    I have a question regardting converting string of numbers to the floating bumbers and plot for voltage vs. weight.
    The load cell for the ADC resolution is 16 bits, and the voltage will be in between +-5 volts.
    The problem, I have the most is converting the string of numbers to the floating numbers, in my case is the weight.
    Attachments:
    tunnelv1.vi ‏139 KB

    When you say "string of numbers" do you mean an array? What is the specific issue you are having? You seem to have orange wires running all over the place. Give a small example demonstrating the problem.
    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

  • Conversion string to float or int

    Hi,
    I have a value "3,000.00 INR" in String type variable.
    Can I get the numeric value i.e. 3,000 in number or float type variable. Because I have to comparison after that with this value.
    Pls give me the solution ASAP.
    Its really urgent.
    Thanks for ur help
    Rahul

    Hi
    844851 wrote:
    I have a value "3,000.00 INR" in String type variable.
    Can I get the numeric value i.e. 3,000 in number or float type variable. Because I have to comparison after that >with this value.---we can convert String to int using Integer.parseInt .
    int projectId=Integer.parseInt(project_id);---project_id is String var..
    Regards
    Meher Irk

  • Converting Vector with Floats to float[] typecast error?

    Java Developers,
    I am able to convert my String vector to a
    String[] but just can't get the Vector with Floats to be converted to a float[] array. I have looked into google and java.sun.com Forums but still cant seem to find the answer. I would really appreciate your help!
    This is how I am making the conversion from Vector(String) to String[]:
    legendLabelsArray = new String[columnHeads.size()];
    int k=0;
    Iterator e = columnHeads.iterator();
    while(e.hasNext()){
    System.out.println("inside the enumerator");
    legendLabelsArray[k] = e.next().toString();
    System.out.println("Array elements at " + k + " are " + legendLabelsArray[k]);
    System.out.println(k++);
    How can I make something similar to work with a Vector with Floats to float[] instead of Strings?
    Thanks,
    Musaddiq
    [email protected]

    Something like this ...
    float[] floatArray = new float[vectorOfFloats.size()];
    int k=0;
    Iterator e = vectorOfFloats.iterator();
    while(e.hasNext()){
    floatArray[k] = ((Float) e.next()).floatValue();
    k++;

  • Not able to convert string attribute to number and date please help me out

    not able to convert string attribute to number and date attribute. While using string to date conversion it shows result as failure.As I am reading from a text file. please help me out

    Hi,
    You need to provide an example value that's failing and the date formats in the reference data you're using. It's more than likely you don't have the correct format in your ref data.
    regards,
    Nick

  • Convert String to Date and Format the Date Expression in SSRS

    Hi,
    I have a parameter used to select a month and year  string that looks like:    jun-2013
    I can convert it to a date, but what I want to do is,  when a user selects a particular month-year  (let's say "jun-2013")
    I  populate one text box with the date the user selected , and (the challenge Im having is)  I want to populate a text box next to the first text box with the month-year  2 months ahead.    So if the user selects 
    jun-2013   textbox A will show  jun-2013 
    and textbox B will show  aug-2013..
    I have tried:
    =Format(Format(CDate(Parameters!month.Value  ),  
    "MM-YYYY"  )+ 2  )   -- But this gives an error
    This returns the month in number format   like "8"    for august...
    =Format(Format(CDate(Parameters!month.Value  ), 
    "MM"  )+ 2  )
    What is the proper syntax to give me the result    in this format =  "aug-2013"  ???
    Thanks in advance.
    MC
    M Collier

    You can convert a string that represents a date to a date object using the util.scand JavaScript method, and then format a date object to a string representation using the util.printd method. For more information, see:
    http://livedocs.adobe.com/acrobat_sdk/9.1/Acrobat9_1_HTMLHelp/JS_API_AcroJS.88.1254.html
    http://livedocs.adobe.com/acrobat_sdk/9.1/Acrobat9_1_HTMLHelp/JS_API_AcroJS.88.1251.html
    In your case, the code would be something like:
    var sDate = "2013-01-10";
    // Convert string to date
    var oDate = util.scand("yyyy-mm-dd", sDate);
    // Convert date to new string
    var sDate2 = util.printd("mm/dd/yyyy", oDate);
    // Set a field value
    getField("date2").value = sDate2;
    The exact code you'd use depends on where you place the script and where you're getting the original date string, but this should get you started.

  • Convert String variable value  to an Object referece type

    Hi all,
    I want to know that if there any possible way to convert String variable value to a Object reference type in java. I'll explain by example if this is not clear.
    Let's think that there is a string variable name like,
    String name="HelloWorld";
    and there is a class name same to the variable value.
    class HelloWorld
    I am passing this string variable value to a method which is going to make a object of helloworld;
    new convertobj().convert("HelloWorld");
    class convertobj{
    public void convert(String name){
    // in hert it is going to create the object of HelloWorld;
    // HelloWorld hello=new HelloWorld(); just like this.
    now i want to do this from the name variable value.( name na=new name()) like wise.
    please let me know if there any possible way to do that.
    I am just passing the name of class by string variable then i wanted to make a instance of the class which come through the variable value.
    thanx.

    Either cast the object to a HelloWorld or use the reflection API (Google it) - with the reflection API you can discover what methods are available.
    Note: if you are planning to pass in various string arguments and instantiate a class which you expect to have a certain method... you should define an interface and have all of your classes that you will call in this way implement the interface (that way you're sure the class has a method of that name). You can then just cast the object to the interface type and call the method.
    John

  • How to convert string to an integer in SQL Server 2008

    Hi All,
    How to convert string to an integer in sql server,
    Input : string str="1,2,3,5"
    Output would be : 1,2,3,5
    Thanks in advance.
    Regards,
    Sunil

    No, you cannot convert to INT and get 1,2,3 BUT you can get
    1
    2
    3
    Is it ok?
    CREATE FUNCTION [dbo].[SplitString]
             @str VARCHAR(MAX)
        RETURNS @ret TABLE (token VARCHAR(MAX))
         AS
         BEGIN
        DECLARE @x XML 
        SET @x = '<t>' + REPLACE(@str, ',', '</t><t>') + '</t>'
        INSERT INTO @ret
            SELECT x.i.value('.', 'VARCHAR(MAX)') AS token
            FROM @x.nodes('//t') x(i)
        RETURN
       END
    ----Usage
    SELECT * FROM SplitString ('1,2,3')
    Best Regards,Uri Dimant SQL Server MVP,
    http://sqlblog.com/blogs/uri_dimant/
    MS SQL optimization: MS SQL Development and Optimization
    MS SQL Consulting:
    Large scale of database and data cleansing
    Remote DBA Services:
    Improves MS SQL Database Performance
    SQL Server Integration Services:
    Business Intelligence

  • How to convert String (dd-MMM-yyyy) to oracle.jbo.domain.Date

    Hi
    Could you please tell how do I convert String of date in format dd-MM-yyyy to ADF date? Please show me some sample.
    Thanks

    http://javaalmanac.com/egs/java.text/FormatDateDef.html
    Once you have a java.util.Date you can convert it to oracle.jbo.domain.Date. (see http://www.fifkredit.com/bc4jdoc/rt/oracle/jbo/domain/Date.html)

  • Facing problem in converting string to date using getOANLSServices()

    I am trying to set a value for date field in my vo and trying to insert into the table.
    In controller I am getting the String which has a date:
    ex: String date="01-NOV-2007";
    while setting into the row I need to convert into Date but it is returning null.
    The below code I used
    to convert into date :
    Date dt = new Date(getOADBTransaction().getOANLSServices().stringToDate(date));
    But this dt is returning a null value is there any solution please advise me.
    Regards!
    Smarajeet

    Smarajeet ,
    See this thread, in one of my replies i have mentioned how to convert string to java.sql.date.You can use the same for oracle.jbo.domain.Date.
    urgent!How to set the default selected date for an OAMessageDateFieldBean
    --Mukul                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

Maybe you are looking for

  • Recebimento parcial em ME sem calculo de diferenças cambiais

    Boa tarde, Gostaria de colocar a seguinte situação: Cliente - moeda local EUR Recebimentos parciais em moeda estrangeira - USD - Exemplo: Para o lançamento de um recebimento parcial em USD, na transação F-28, o cliente preenche os campos: moeda/taxa

  • Relation between Invoice Line items and Accounting Line item

    Dear All, My requirement is to print all the invoice documents and it's tax values like cenvat, Ecess, BED and VAT. I have to fetch these tax details from BSEG table . I' am getting Invoice number ( RBKP-BELNR ) from BKPF-AWTKEY . Can any one please

  • [Solved] Old Thinkpad Laptop with HPA LCD + SM712

    I have some problem configuring X on an old laptop (IBM Thinkpad 1161-237 i series 1200 with an HPA LCD 12.1" 800x600 max resolution) ... I tried everything. I can start X, but I have a mess on the screen ... you can see the windows, but there are li

  • Can you assign field values as the file name

    When filling fillable pdf forms I would like to assign the name of the file (automate a Save As) to field values. 

  • Firefox is extremely slow on first start up

    http://www.youtube.com/watch?v=NYw4oHHGqJA That is literally how it looks in realtime when I first start firefox. No such problem in Chrome. So when I choose first link from bookmarks or fast dial, it takes minutes to load it and in the meantime fire