Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 02-11-2008, 03:48 PM
Member
 
Join Date: Feb 2008
Posts: 2
durahman is on a distinguished road
String to Float
I had been browsing the forum to get ideas from members.

I was trying to do some validations on input entered by users through a form. Validation involve say Input fields must not empty and one must be an Integer and one must be a float.

Field must not empty works fine.
One Input must be an Integer works fine.

Problem when come to float it seem my coding does not working the way I want it.

Here is part of the validation code:

Code:
public boolean validate() { boolean allOk=true; if (noreg_majikan.equals("")) { errors.put("noreg_majikan"," Perlu diisi."); noreg_majikan=""; allOk=false; } if (bil_kosong.equals("")) { errors.put("bil_kosong"," Perlu diisi."); bil_kosong=""; allOk=false; }else { try { int x = Integer.parseInt(bil_kosong); } catch (NumberFormatException e) { errors.put("bil_kosong","Perlu dalam bentuk angka"); bil_kosong=""; allOk=false; } } if (gaji.equals("")) { errors.put("gaji"," Perlu diisi."); gaji=""; allOk=false; }else { try { float y = Float.parseFloat(gaji); } catch (NumberFormatException e) { errors.put("gaji","Perlu dalam bentuk angka"); gaji=""; allOk=false; } } return allOk; }
For the float part if the field not entered (empty) it give the correct message. If I enter a String it give the correct message.

When I entered 9 ( or any integer) it works. But when I entered say 99.50 it give error as if I had entered a String.

I just want to know why?

Thanx
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 02-11-2008, 04:42 PM
hey hey is offline
Member
 
Join Date: Dec 2007
Posts: 21
hey is on a distinguished road
Did you try to enter 99,50 instead of 99.50?

I don't know, just guessing

Why don't you use Scanner? It should be much faster with it
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 02-12-2008, 02:17 AM
Member
 
Join Date: Feb 2008
Posts: 2
durahman is on a distinguished road
When I tried it again it works.

99,50 it gives a String error.

Since I am new to java, I will explore the use of scanner.

Thanks Hey.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Float to String mew New To Java 4 12-29-2007 07:08 PM
convert string to float miss_dot NetBeans 1 11-15-2007 01:26 AM
Error with convert to Float cachi New To Java 1 08-06-2007 04:18 AM
Help with valid declarations of a float baltimore New To Java 1 07-31-2007 12:28 PM
Class float Peter New To Java 1 07-08-2007 03:17 AM


All times are GMT +3. The time now is 01:44 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org