I need to be able to capture decimals with only 2 digits after the decimal
point java, tried this
This is my code , i need to know be able to read with 2 decimal places
package project.pkg1;
import javax.swing.JOptionPane;
/**
* @author Maria Andrea Quintana 4891405 *
* @author Salvador Frias
*/
public class Project1 {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
String s1 = JOptionPane.showInputDialog("Enter the purchase amount");
if (s1 == null) {
JOptionPane.showMessageDialog(null, "You must enter a valid integer");
System.exit(0);
}
if (s1.isEmpty()) {
JOptionPane.showMessageDialog(null, "You must enter a valid integer");
System.exit(0);
}
for (int i = 0; i < s1.length(); i = i + 1) {
if (!Character.isDigit(s1.charAt(i))) {
JOptionPane.showMessageDialog(null, "You must enter an integer value");
System.exit(0);
}
}