double depositAmount = Double.parseDouble(etDepositAmount.getText().toString());
BigDecimal depositAmountSafe = BigDecimal.valueOf(depositAmount);
BigDecimal userBalance = BigDecimal.valueOf(user.getBalance());
int comparisonResult = depositAmountSafe.compareTo(userBalance);
if (comparisonResult > 0) {
Toast.makeText(contex, R.string.INSUFFICIENT_BALANCE, Toast.LENGTH_SHORT).show();
return;
}
Deposit deposit = createDeposit();
In the above piece of code, I should be able to create a deposit if only the entered sum for the amount is less or equal to the user's balance. But for example if the user's balance is 62921.0, I am able to enter 62921.0000000000000001 and get the deposit created. How do I set the number of decimals? And if not, how can I enforce that the user can only enter a maximum number of digits as decimals. For example a maximum of 3 digits to the right of a a decimal point(eg. x.123 and not x.1234) for an EditText.