如何将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)
}发布于 2018-09-05 12:58:50
您可以这样做:
Java代码:
MutableLiveData<Long> longValue = new MutableLiveData()
LiveData<Double> getDecimalAmt(){
return Transformations.map(longValue) { (double)(it /100) }
}Kotlin代码:
var longValue: MutableLiveData<Long> = MutableLiveData()
fun getDecimalAmt(): LiveData<Double> = Transformations.map(longValue) { it.div(100).toDouble() }https://stackoverflow.com/questions/52185314
复制相似问题