bigdecimal转换为integerjava数字转换成字符串⼀、各种数字类型转换成字符串型:
public static void main(String[] args) {
double value = 123456.123;
String str = String.valueOf(value); // 其中 value 为任意⼀种数字类型。
System.out.println("字符串str 的值: " + str); //字符串str 的值: 123456.123
}
⼆、字符串型转换成各种数字类型:
public static void main(String[] args) {
String s = "2";
byte b = Byte.parseByte( s );
short t = Short.parseShort( s );
int i = Integer.parseInt( s );
long l = Long.parseLong( s );
Float f = Float.parseFloat( s );
Double d = Double.parseDouble( s );
}
三、扩展,⼤数类型与字符串之间的转换
import java.math.BigDecimal;
public class Test {
public static void main(String[] args) {
String doubleStr = "44444.55555";
//String类型转成bigdecimal类型
BigDecimal bignum = new BigDecimal(doubleStr);
//实现bigdecimal类型转成String类型:
String str = String();
System.out.println("str 的值是: " + str);  //str 的值是: 44444.55555
//设置⼩数位数,第⼀个变量是⼩数位数,第⼆个变量是取舍⽅法(四舍五⼊)
BigDecimal bd=bignum.setScale(2, BigDecimal.ROUND_HALF_UP);
System.out.println(bd);  //44444.56
}