Updated code for pdf table issue
This commit is contained in:
@@ -5,6 +5,8 @@ import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Type;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.SecureRandom;
|
||||
import java.text.DecimalFormat;
|
||||
import java.text.NumberFormat;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.time.LocalDate;
|
||||
@@ -414,4 +416,29 @@ public class Utils {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
public static String convertItalianAmountToDouble(String amount) throws NumberFormatException {
|
||||
// Step 1: Remove the thousands separator and replace the decimal separator
|
||||
String normalizedAmount = amount.replace(".", "").replace(",", ".");
|
||||
|
||||
// Step 2: Parse the string to a double
|
||||
double value = Double.parseDouble(normalizedAmount);
|
||||
if (value <= 0) {
|
||||
return amount;
|
||||
}
|
||||
// Step 3: Format the double to 2 decimal places
|
||||
DecimalFormat decimalFormat = new DecimalFormat("#.00");
|
||||
return decimalFormat.format(value); // Return formatted string
|
||||
}
|
||||
public static boolean isItalianFormattedAmount(String input) {
|
||||
// Regular expression to match Italian-style amounts (e.g., 41.003,00 or 123,45)
|
||||
if (!input.contains(",")) {
|
||||
return false; // Return false if there is no comma
|
||||
}
|
||||
String sanitizedInput = input.replace(",", "");
|
||||
|
||||
// Step 2: Check if the remaining string is a whole number
|
||||
String wholeNumberPattern = "^\\d+$"; // Regex to match whole numbers
|
||||
|
||||
return sanitizedInput.matches(wholeNumberPattern);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user