How to convert a decimal to a string in Java?
You can use the toString() method to convert a BigDecimal object to a String type. Here is an example:
import java.math.BigDecimal;
public class Main {
public static void main(String[] args) {
BigDecimal decimal = new BigDecimal("10.5");
String str = decimal.toString();
System.out.println(str); // 输出: 10.5
}
}
In the example above, we created a object of type BigDecimal called “decimal”, then converted it to a string using the toString() method, and finally printed out the result.