Table of Contents
In this post, we will see how to convert String to BigDecimal in java.
It is very simple to convert String to BigDecimal in java. You can simply use BigDecimal ‘s String based constructor to do it.
1 2 3 |
BigDecimal(String val) |
Above constructor convert String representation of BigDecimal to BigDecimal
Let’s see this with the help of example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
package org.arpit.java2blog; import java.math.BigDecimal; public class StringToBigIntegerMain { public static void main(String[] args) { String currency="13.23"; BigDecimal bigDecimalCurrency=new BigDecimal(currency); System.out.println("Converted String currency to bigDecimalCurrency: "+bigDecimalCurrency); } } |
When you run above program, you will get below output:
Converted String currency to bigDecimalCurrency: 13.23
that’s all about converting String to BigDecimal.
You may also like:
Was this post helpful?
Let us know if this post was helpful. Feedbacks are monitored on daily basis. Please do provide feedback as that\'s the only way to improve.