English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
Überprüfen Sie, ob die Benutzer-Eingabe mindestens N Dezimalstellen enthält.
1Wenn der Benutzer eine nicht-numerische Eingabe vornimmt, wird eine Ausnahme ausgelöst und false zurückgegeben.
2.When the user enters a number, judge whether it contains at least N decimal places. If it does not contain, return false.
3.When the decimal places of the number entered by the user are greater than or equal to N, return true.
public class ddouble { public static void main(String args[]) { String str = " .1124 "; boolean sfdouble = doubleyn(str,4); System.out.println(sfdouble); } public static boolean doubleyn(String str,int dousize){ try { double num=Double.valueOf(str);//Convert the string to a number by force if(str.trim().indexOf(".")=== -1{ return false; } int fourplace = str.trim().length() - str.trim().indexOf(".") - 1; if(fourplace<dousize){ return false; } return true; } } return false;//If an exception is thrown, return False } } }
This example of the java judgment of whether the user input contains at least N decimal places is all the content that the editor shares with everyone. I hope it can give you a reference, and I also hope that everyone will support the Yelling Tutorial.
Declaration: The content of this article is from the Internet, and the copyright belongs to the original author. The content is contributed and uploaded by Internet users spontaneously. This website does not own the copyright, has not been manually edited, and does not assume any relevant legal liability. If you find any content suspected of copyright infringement, please send an email to: notice#oldtoolbag.com (Please replace # with @ when sending an email to report abuse, and provide relevant evidence. Once verified, this site will immediately delete the infringing content.)