Regarding Float.parseFloat method

Hi,
i have two text boxes,one is Quantity another Price i want Qantity as integer and Price as float while giving input.
if user giv other than those i need to display error for that i done for Integer.parseInt(getparameter(..)) for this if the string is not int,it raising exception but for Float.parseFloat(getparameter(..)) for this it is not raising any exception.i am not getting what is the reason for that
Thanks in advance
nagaraju

if(this.price==null||this.price.equals(""))
ActionError ae1=new ActionError("pricereq");
aes.add("price",ae1);
else{
*try{*
*System.out.println(this.price);*
*Float.parseFloat(this.price);*
*catch(Exception e)*
*ActionError ae2=new ActionError("pricenotfloat");*
*aes.add("price",ae2);*
}I wrote that code in struts to validate the form, in that when i entered the integer value in price text field it must show price must be float. but exception not raising in that highleted part
i w

Similar Messages

  • Error Converting "1,300" to Float using Float.parseFloat()

    I need to convert a string in the format xx,xxx.00 to a float value.
    But I get java.lang.NumberFormatException by using Float.parseFloat("xx,xxx.00")
    What can I do?

    Look at java.text.NumberFormat to parse numbers in a specific format.
    regards,
    Owen

  • Float.parseFloat

    I am compiling my code with jdk 1.3 and getting this error when I compile:
    Error: cannot resolve symbol: method parseFloat (java.lang.String) in class java.lang.Float
    My class path:
    .;C:\jdk13\lib\;C:\jdk13\lib\tools.jar;C:\jdk13\lib\dt.jar;C:\jdk13\jre\lib\rt.jar;C:\jdk13\jre\lib\i18n.jar
    And here is my method...
    public void setGrandTotal(String f){
    this.grandTotal=Float.parseFloat(f.trim());
    Can some one tell me why can not resolve parseFloat
    Thank you

    When I compile your method in isolation, it compiles fine. Have you checked for syntax errors above it in the code? Does the code compile clean if you comment out that method?
    Normally you do not need to specify the java libraries in your classpath. Have you tried compiling with "javac -classpath . file" ?

  • Null pointer Exception with Float.parseFloat

    I need to assign a float value from a database to a variable recurrently throughout a while loop. but i am getting a null pointer exception error:
    while ( rs.next() )
         out.println("<TR>");
              float corr = Float.parseFloat((String) request.getParameter("echo"));
              out.println("<center><TD><b><font color = #990000>" + rs.getString("race_number") + "</b></TD>");
              out.println("<center><TD><b><font color = #990000>" + rs.getString("sail_number") + "</b></TD>");
              out.println("<center><TD><b><font color = #990000>" + rs.getString("finish_time_elapsed") + "</b></TD>");
              out.println("<center><TD><b><font color = #990000>" + rs.getString("echo") + "</b></TD>");
              out.println("</TR>");
    I've also tried:
    float corr = Float.parseFloat( String request.getParameter("echo"));
    float corr = 0;
    corr Float.parseFloat((String) request.getParameter("echo"));
    corr = echo;
    corr = request.getParameter("echo");
    corr = rs.getString("echo");
    corr = Float.parseFloat(request.getParameter("echo"));
    temp = rs.getFloat("Problem_Description");
    Any ideas Please!!!

    Null pointer exception means that the value you are trying to turn into a Float is null. Probably request.getParameter("echo") returns null.
    Is "echo" a request parameter, or a field you want to get from the database?
    request.getParameter() has nothing to do with a database query.
    That is your http request coming from the form submission. It won't change.
    If "echo" is meant to be a request parameter, then make sure the parameter is actually present.
    If its a database field (stored as a number) then
    float corr = rs.getFloat("echo");
    should do the trick.
    Can the value be null in the database?
    Cheers,
    evnafets

  • Issue with Float.parseFloat

    Hi,
    I tried the following code. Float.parseFloat("23d")does not throw an exception. The below code prints output as 23.0.
    String s = new String ("23d");
    try{
    System.out.println(Float.parseFloat(s));
    catch(Exception e){
    System.out.println("not a number..");
    How can I make Float.parseFloat("23d") throw an exception? Please help.
    thanks.
    roshni.

    here the d determine that this is double variable.
    so this is not give any exception.
    if you use any other character then it throw the exception.

  • Regarding DocumentBuilder.parse method returns reference as null value.

    Hi
    We are in the process of migrating code which works on WebSphere/JBOSS to WLS..
    We are using DocumentBuilder object for parsing the Locale related xml data. I understand that the DocumentBuilder is provided by DocumentBuilderFactory which is an interface whose implementation is server specific.
    But when the Document Builder parse method is called with a valid file path, we are getting System.Out of doc.getFirstChild().getLocalName() as null (which ideally should have been the name of the first node). No Errors are observed .
    For WLS, the parser is giving the document object reference as null whereas in other servers like Websphere and JBOSS we are able to parse the same xml with proper object reference.
    Could you please help in this regard?
    Thanks and regards
    Anil

    Hi Vmotamar,
    If you think that the parsers available as part of WebLogic are causing the issues, Then you can use your Own Parsers while migrating to WebLogic Server. I mean Get the Parser Jar files which u used as part of JBoss or WebSphere and put it inside the "APP-INF\lib" directory of your EAR Application or Put them inside "WEB-INF\lib" of your WEBApplication...and then Apply ClassLoader Filtering feature provided by WebLogic ...which allows an application to use It's Own Jars\Classes ...
    Please refer to: http://forums.oracle.com/forums/thread.jspa?threadID=1109267&tstart=150 and in http://weblogic-wonders.com/weblogic/parsers_issues
    Thanks
    Jay SenSharma
    http://weblogic-wonders.com/weblogic/parsers_issues/ (WebLogic Wonders Are Here)

  • Float.parseFloat("173879.04")

    Why it returns 173879.05 ? IS THIS a bug in Java ?

    Yes, agree, I have done something similar for adding double, and java
    'kill' me.
    BigDecimal is a good way, if and only if you pass 'string' to constructor, else it still add wrong double...
    So read input as string instead and catch some exceptions...
    I have an example of it when doing GUI.
    I also, use some method to try fix but lead to losing precision, such as
    double b;
    double c;
    int a = int (b * 100);
    c = a / 100;
    Or if you need to use GUI, then java.text.* will help...

  • Regarding BADI  INVOICE_UPDATE, method CHANGE_AT_SAVE

    Hi there,
    I'm implementing this Badi so i can make some checks at the time of saving an edited preliminary (parked) document. If the total of the invoice is higher than the old one, i do the checks (against a Z table, a Z function module, etc) and if i have to stop saving, i trigger an error message raising ERROR_WITH_MESSAGE exception. As the only method that gets called in all the cases I need, and allows me to trigger messages, is CHANGE_AT_SAVE, I use this one.
    The okcodes that i'm interested in are:
    <i>PARK (Save parked document)
    COMP (Save as completed)
    BU (Post)</i>
    The problem is, to do all the processing, i compare the method parameters
    S_RBKP_OLD vs. S_RBKP_NEW.
    When the okcode is PARK or COMP it's ok, but <b>when posting (BU) the S_RBKP_OLD doesn't get populated</b>! Anyone knows why is that and what the workaround would be?
    Update: i've searched throught OSS but there's no note related to this.
    Thank you very much.

    Hi Narendran, thanks for your help,
    But my problem is that i need to compare the new total of the invoice (s_rbkp_new-rmwwr) versus the old one (s_rbkp_old-rmwwr), so that if the new one is higher, i check that the difference between them is not higher than a set limit, otherwise i must stop saving/posting.
    I could retrieve the values from RBKP table itself (which should still be the "old" ones at the time the BADI executes) but then, what is s_rbkp_old for?
    Edit: Requirements changed and now i need to do the checks for every changed line of the invoice. As in the original problem, when posting, TI_RSEG_NEW has all the new values but TI_RSEG_OLD is initial. I've been debugging a little and got to the MRM_DOCUMENT_CHANGE_PREPARE function, which is not calling the MRM_*_READ functions since i_xupda (update flag) is 'I' when posting, although no new line has been inserted.
    PLEASE, if you implemented this BADi method before, post your comments or example code. Documentation is scarce and on the internet there isn't much info neither.
    I've been also looking at exits but they don't seem to serve this purpose.
    By the way, i'm on 4.6C.
    Many thanks

  • Doubt regarding on main method

    is it possible to invoke a main method from the other class.....

    I have done it. Is it through this way u ppl were talking abt:
    class FinalVariable{
    void variable()
    System.out.println("FINAL =");
    Change.main(new String[] {"sd"});
    public class Change{
    public static int A = 1;
    public static void main(String[] args){
    FinalVariable fv=new FinalVariable();
    for(;A<=1;A++)
    A=2;
    fv.variable();
    System.out.println("CHANGED VALUE OF CM_PER_INCH=");
    }

  • Querry regarding overriding static methods

    Hi ,
    I m overriding a static method defined in superclass ThreadLocal1 as:
    public static void mm()
         System.out.println("bye");
    class Thread1 extends ThreadLocal1{
    tt(){}
    public static void mm()
         System.out.println("hi");
    public static void main(String args[])
         Thread1 t1= new Thread1();
         ThreadLocal1 th1;
         th1=t1;          // t1 is assigned      th1.mm();
         t1.mm();
    }output is : bye
    hi
    I am not getting why ref var th1 is not calling overridden method mm() when th1 is assigned t1 that is subclass instance.
    when i m removing static modifier from mm(0 in superclass then output is : hi hi
    plz clarify why is it so.....
    Edited by: jawatch on Oct 29, 2007 7:01 AM

    jawatch wrote:
    @kajbj :
    but i have overridden static method mm()No, you haven't. You've hidden it. Overriding only applies to non-private, non-final, non-static methods, and they are the only case where you can see the kind of polymorphism you're talking about.

  • Regarding float type

    why I can't write like this
    float f = 3.506;
    where as I can write like float f = 3;

    Do a search for data width. By default any floating point decimal number is assigned 64 bits (as with double) and a whole number 32 bits (as with int). Float is a signed 32 bit floating point decimal so it isn't wide enough without an explicit call such as;-
    float f = 32.1F;
    float f = 32.1Ff; or
    float f = (float)32.1;
    As a rule of thumb make all your numbers int or double unless you have a very good reason to do otherwise

  • Regarding the abs methods

    Can anyone tell me. please......What are the differences between the different abs methods i.e.public static int abs(int a) ,public static int abs(double a)......so on?

    corlettk wrote:
    Not very enlightening...
    public boolean equals(Object obj) {
         return obj instanceof Double
                && doubleToLongBits(((Double)obj).value) == doubleToLongBits(value);
    public static long doubleToLongBits(double value) {
         long result = doubleToRawLongBits(value);
         // Check for NaN based on values of bit fields, maximum exponent and nonzero significand.
         if (   ((result & DoubleConsts.EXP_BIT_MASK) == DoubleConsts.EXP_BIT_MASK)
    && (result & DoubleConsts.SIGNIF_BIT_MASK) != 0L)
             result = 0x7ff8000000000000L;
         return result;
    }Bit twiddling was never my strong point... WTFsa "nonzero significand"... WTFsa "significand" for that matter... sounds like a bloke with "self important metacarpal syndrome" to me.
    I read 0x7ff8000000000000L as chinese for Far King Big Number (am I warm) but then +(FKBN == FKBN) == true+ so HTF does NaN != NaN ... Honestly, I shouldn't worry about such things, I should accept the fact that I'm not bright enough to understand the answers and move into something simpler, like brain surgery... Nurse, have you seen my chewing gum?
    Cheers. Keith.Actually working out the bits for doubles is way more effort than I'm willing to exert. However, consider this:
    Some of the bits in a double make up what is roughly called the mantissa or the significan, e.g. 1.25, a some bits make up the exponent, e.g., 67, in 1.25 * 2^67. There are rules for which bits correspond to which parts, and how the bits are interpreted, and with a few samples and a basic knowledge of the structure, you could deduce the rest. The language defines the rules, and they follow a certain pattern.
    However, certain values do not fit into that pattern. You can see how 1.0 / 2.0, 1.0 / 4.0, ... , 1.0 / 256.0 etc. fit into the pattern. You'll also discover that 1.0 / 0.0 doesn't fit in. BUT, it's still useful to represent the value obtained by 1.0 / 0.0, and so, there's a special bit sequence that doesn't fit the pattern that is defined to represent that quantity--Double.INF, or something like that.
    Likewise, certain quantities like 0.0 / 0.0 don't fit the pattern, but still it might be useful to know what result was obtained, so it's defined by the language that a particular bit sequence does not fit the pattern, but instead represents that quantity, and it is known as Double.NAN.

  • How to extract an integer or a float value from a String of characters

    Hi i have a problem getting to a float value within a string of characters..
    for instance the string is
    "numberItem xxxxxxxxx 700.0" (each x is a space..the forum wouldnt let me put normal spaces for some reason)
    how do i store 700.0 in a float variable
    remember the string is obtained from an inputfile
    so far i got the program to store the inputfile data line by line in a String array..i tried tokenizing the string to get to the the float value but since i have mulitple spaces within my string, the token method only gets "numberItem" from the above String
    This is all i have so far:
    String c;
    String Array[] =new String[g]; (i used a while loop to obtain g(the nubmer of lines in the file))
    while((c=(cr.readLine()))!=null)
    Array[coun]=c;
    it would be reallllllllllllllllllllllllllllllllllllllly easy if there was a predefined method to extract numeric values from a string in java..
    Edited by: badmash on Feb 18, 2009 5:50 PM
    Edited by: badmash on Feb 18, 2009 5:50 PM
    Edited by: badmash on Feb 18, 2009 5:55 PM

    badmash wrote:
    Hi i have a problem getting to a float value within a string of characters..
    for instance the string is
    "numberItem xxxxxxxxx 700.0" (each x is a space..the forum wouldnt let me put normal spaces for some reason)
    with the space included
    how do i store 700.0 in a float variable
    remember the string is obtained from an inputfile
    so far i got the program to store the inputfile data line by line in a String array..i tried tokenizing the string to get to the the float value but since i have mulitple spaces within my string, the token method only gets "numberItem" from the above StringHuh?
    Not true.
    Anyway why not use string split, split on spaces and grab the last element (which by the format you posted would be your 700.0)
    Then there is the Float.parseFloat method.
    It is easy.
    And another thing why not use a List of Strings if you want to store each line? (And why did you post that code which doesn't really have anything to do with your problem?) Also in future please use the code formatting tags when posting code. Select the code you are posting in the message box and click the CODE button.

  • Help!How to analyse a String?

    I got text in Strings and i want to know if each word are a "date", a "int", "currency",etc...
    So i want to know if Java gots methods to determine the type of each words of my strings.
    In another words, i just want to know if i can do something like:
    String str = "1234";
    boolean bool = str.isInt();
    Any help would be greatly appreciated.
    Best Regards
    A.Santos

    Hi! Here's how you can implement some methods of your own. The following methods checks if the given string represents an integer.
    boolean isInteger( String s )
       int i;
       boolean fReturn = true;
       try
          i = Integer.parseInt( s );
       catch( NumberFormatException x )
          fReturn = false;
       return fReturn;
    }For doubles and floats, use the Double.parseDouble() and Float.parseFloat() methods.
    To check if a string represents a date, look at Q.120 in the Question of the Week archives. I've illustrated how to use the java.text.SimpleDateFormat class to convert from the string format to a date format. In this case, you'll have to check for ParseException if the string does not represent a date.
    Hope this helps! If something's not very clear, feel free to ask.
    Cheers!

  • Decimal notations : Urgent

    Hi,
    I have developed a sales application in java. It was initially done for UK. I am using lot of number calculations, floating numbers etc. Now, the software is required for Germany, the problem is with the decimal notation. The notation in Germany is a comma, and it is a period(.) in the UK. So, 1,000 is read as Thousand in the UK and 'One' in Germany.
    The numerous Float.parseFloat methods and other methods return exceptions, if comma is given as a decimal separator.
    Since the application is already live in the UK and just about to go live in germany, I dont have the time to do major changes. But I suppose that as Java is used by the international community, there should be an easy way round.
    Any ideas?
    Thanks a lot

    Mark,
    Thanks for the reply.
    But in which class is the setLocale method?
    Sorry if I sounded dumb..but please help..
    Thanks a lot

Maybe you are looking for