How can I change a String into a BigDecimal
?
The BigDecimal(java.lang.String) constructor accepts a String
argument.
It converts the string representation of a BigDecimal
into a BigDecimal
. The string can include a sign (+ or -), decimal digits (the integer part), fraction, and exponent.
For example,
String amountStr = "124.20";
BigDecimal amount = new BigDecimal(amountStr);
Update
In response to your comment
Converting String in JSP to BigDecimal in ActionClass
From docs TypeConversion-BuiltinTypeConversionSupport
Type Conversion is handled by XWork.
XWork supports automatic type conversion for common types including converting to and from Strings for various data types such as boolean, char, integer, float, double, dates, arrays, collections, Enums, BigDecimal, and BigInteger.
For arrays, the conversion is performed on each individual element. If a conversion cannot be done, standard error reporting will indicate the issue.