[Solved] Adding +1 to the end of a String


Parse the value as a whole and then add the value you desire.

new BigDecimal(/* your string */).add(BigDecimal.ONE)

Or if I read your code correctly, you always want to add new BigDecimal("0.001").

EDIT: if you really want to just change the last digit, use something like the following:

public BigDecimal incrementLastDigit(String value) {
    BigDecimal decimal = new BigDecimal(value);
    return new BigDecimal(decimal.unscaledValue().add(BigInteger.ONE), decimal.scale());
}

Samples:

incrementLastDigit("1234.1234"); // gets you 1234.1235
incrementLastDigit("1234.1"); // gets you 1234.2
incrementLastDigit("9999999999999999999999999999999999.99999999999999999999999999999"); 
// gets you 10000000000000000000000000000000000.00000000000000000000000000000

3

solved Adding +1 to the end of a String