Controle de type en java
elhila
Messages postés
32
Statut
Membre
-
danimo -
danimo -
s'il vous plai, est c qu'il y a une fonction java qui faire le controle sur la valeur d'un champ qui doit etre un numérique !!
Configuration: Windows XP Internet Explorer 6.0
9 réponses
-
Salut !
C'est peut-etre trop tard, mais avec ce bout de code c'est une solution :
try
{
lentree = Integer.parseInt(entree); // si String entree non num. >>> exception
}
catch (NumberFormatException f)
{
System.out.println(entree + " non numerique.");
return "";
} -
salut
certainement mais que contient ton champ ???
un chaine de caratère ?
-
si c'est le cas
voici une méthode statique de la classe Integer par exemple
valueOf public static Integer valueOf(String s) throws NumberFormatExceptionReturns an Integer object holding the value of the specified String. The argument is interpreted as representing a signed decimal integer, exactly as if the argument were given to the parseInt(java.lang.String) method. The result is an Integer object that represents the integer value specified by the string. In other words, this method returns an Integer object equal to the value of: new Integer(Integer.parseInt(s)) Parameters: s - the string to be parsed. Returns: an Integer object holding the value represented by the string argument. Throws: NumberFormatException - if the string cannot be parsed as an integer.
pour toutes les classes représentant une primitive numérique la même méthode existe
-
il doit contenir un numérique (entier), mais l'utilisateur peut faire une faute de frappe et saisie une chaine de caractéres..!
-
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre question -
donc tu peux tester avec cette méthode sans problème
-
http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Integer.html
-
-
ben c'est la documentation java officielle
euh? j'ai jamais travaillé (ni trouvé d'ailleurs) l'équivalent en français
-