checking for no value

Posted on 2006-05-17
Last Modified: 2010-04-01
I have a small snippett of coding that is confusing me.
I want to check to make sure the sqty and ssell have values and are not empty
It phews big time and I do not know why. It does not the comparsion and does not like my error message to the user..:((
How would I check to ensure it is numeric??
Can someone please help me??

sqty = new Integer(request.getParameter("soldqty"))
ssell = new Float(request.getParameter("sellprice"));
 if (sqty != 0  &&  ssell != 0 ) {
     stot1 = new Float(sqty.intValue()*ssell.floatValue());
Question by:bearpaws
    LVL 27

    Accepted Solution

    You could use something like the following.
    String soldqty = request.getParameter("soldqty");
    String sellprice = request.getParameter("sellprice");
    if(soldqty != null && sellprice != null){
                        int sqty = Integer.parseInt(soldqty);
                        float ssell = Float.parseFloat(sellprice);
                        float stot1 = ssell * sqty;
                      } catch(NumberFormatException nfe){
                                          out.println("SOLD PRICE OR SOLD QUANTITY INVALID");
    }else {
           out.println("SOLD PRICE OR SOLD QUANTITY NOT SENT");

    Author Comment

    that worked pretty good!
    When I print a line using out.println, All my error messages end on the same line.
    I thought you used out.newlin() to skip down a line.
    Could you clarify that point for me??
    thank you again

    Author Comment

    I figured it out!

    Featured Post

    Top 6 Sources for Identifying Threat Actor TTPs

    Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

    Join & Write a Comment

    Suggested Solutions

    In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
    DECT technology has become a popular standard for wireless voice communication. DECT devices are not likely to be affected by other electronic devices and signals because they operate in a separate frequency-band.
    how to add IIS SMTP to handle application/Scanner relays into office 365.
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

    733 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now