BigDecimal与Long之间的转换新建了⼀个class类取名叫Firut
import java.math.BigDecimal;
public class Firut {
private String id;
private BigDecimal price;
private long much;
private int choose;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public BigDecimal getPrice() {
return price;
}
public void setPrice(BigDecimal price) {
this.price = price;
}
public long getMuch() {
return much;
}bigdecimal转换为integer
public void setMuch(long much) {
this.much = much;
}
public int getChoose() {
return choose;
}
public void setChoose(int choose) {
this.choose = choose;
}
public static void main(String[] args) {
Firut firut = new Firut();
long price = 1000;
BigDecimal b = new BigDecimal(100);
firut.setId("1");
//long转换成BigDecimal
firut.setPrice(new BigDecimal(price));
//BigDecimal转换成long
firut.setMuch(b.longValue());
//BigDecimal转换成int
firut.setChoose(b.intValue());
System.out.Price());
}
}
注意转换的精度问题
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论