如何将金额从1000转换为10.00?
private MutableLiveData<Long> amt = new MutableLiveData<>();
public void setAmt(long value) {
amt.postValue(value);
}
public LiveData<Long> getAmt() {
return amt;
}
public LiveData<Double> getDecimalAmt() {
// How to convert long to decimal?
// (amt / 100)
}
答案 0 :(得分:2)
您可以使用以下方法:
Java代码:
MutableLiveData<Long> longValue = new MutableLiveData()
LiveData<Double> getDecimalAmt(){
return Transformations.map(longValue) { (double)(it /100) }
}
科林代码:
var longValue: MutableLiveData<Long> = MutableLiveData()
fun getDecimalAmt(): LiveData<Double> = Transformations.map(longValue) { it.div(100).toDouble() }