Answers for "java check doubles"

1

how to check if string is double or not in java

String decimalPattern = "([0-9]*)\\.([0-9]*)";  
String number="20.00";  
boolean match = Pattern.matches(decimalPattern, number);
System.out.println(match); //if true then decimal else not
Posted by: Guest on October-01-2021
0

how to compare doubles in java

private static void testBdEquality() 
{
     BigDecimal a = new BigDecimal("2.00");
     BigDecimal b = new BigDecimal("2.0");
 
     System.out.println(a.equals(b));           // false
 
     System.out.println(a.compareTo(b) == 0);   // true
}
Posted by: Guest on September-10-2021

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language