getParameter getValue and floats

Discussions

Web tier: servlets, JSP, Web frameworks: getParameter getValue and floats

  1. getParameter getValue and floats (6 messages)

    hi all,

    i do have a form where i enter a float that can have more then 15 fraction digits, due to important rates that need so much digits.

    i have no problem to display it from a database.
    the problem is when i take this value from the form. if there is more then 17 numbers after the point, the rest is not taken.


    (example : 0.123456789123456789 returns me 0.1234567891234567 (89 is missing))
    i do use this method to get the form value :
    myObj.EOLY=request.getParameter("eoly");

    is my number cuted because i do use getParamter that returns a string and not a float or a number ? is getValue different ? what method should i use not to change the number ?

    Threaded Messages (6)

  2. getParameter getValue and floats[ Go to top ]

    Two suggestions...
    First make sure your method for the form is a "post" not a "get". A "get" has a set length of characters that can be passed where a "post" does not.

    Second make sure your text input field in the form doesn't have a max length set. There is no reason that the number should be truncated because it is being returned as a string. You should be able to type in a sentence in that same field and each character should be returned. Hope this helps.

    dan
  3. getParameter getValue and floats[ Go to top ]

    i have checked your suggestions :
    i do use post method

    (<form name = "myForm" ACTION="/MyWebApp/servlet/MSSQLpack.GetCookie" METHOD="POST"> ) <-- that's my code

    and here is the way i set my input :

    <td align="middle"><input name="eom01" value=""> </td>

    so both conditions are here. i don't see why it's cuted after the decimal number 17
  4. getParameter getValue and floats[ Go to top ]

    make sure to put in the type of input ex.
    <input type="text" name="whatever" value="">
    then try typing in a sentence with more the 17 characters and see if it gets returned correctly.
  5. getParameter getValue and floats[ Go to top ]

    Are you noticing the loss after you convert the result into a double? The double data type only can express about 16 or 17 digits of accuracy because the entire number (including exponent) is packed into 64 bits. Try using a java.math.BigDecimal, which has arbitrary precision.

     - Nathan
  6. getParameter getValue and floats[ Go to top ]

    well in fact i have tested this :

    searchResp.EOLY=request.getParameter("eoly");
    BigDecimal bd = new BigDecimal(searchResp.EOLY);
    out.println(bd);
    (searchResp.EOLY is a String)

    the result is the same : the number is truncated after the 16 first digits.
    the problem may be when i use getParameter, it converts the number into a String, then if i use BigDecimal, it's too late, the number has already been truncated i think.

    i maybe forgot to say that i do have the "eoly" parameter in my jsp and i use getParameter("eoly") in my servlet.

    any more clues ??
  7. getParameter getValue and floats[ Go to top ]

    well i think i've found the solution
    i think that the problem is with my databse, SQL server, that only takes 17 digits for a float