添加单价和金额计算
This commit is contained in:
@@ -33,6 +33,17 @@ private fun Double.roundToDouble(decimalPlaces: Int): Double {
|
||||
return kotlin.math.round(this * factor) / factor
|
||||
}
|
||||
|
||||
private fun Float.roundToDouble(decimalPlaces: Int): Double {
|
||||
val factor = 10.0.pow(decimalPlaces)
|
||||
return kotlin.math.round(this * factor) / factor
|
||||
}
|
||||
|
||||
fun Float?.toSafeString(unitName: String?): String {
|
||||
if (this == null || this == 0f) return ""
|
||||
val decimalPlaces = getDecimalPlaces(unitName)
|
||||
return "%.${decimalPlaces}f".format(this)
|
||||
}
|
||||
|
||||
fun Double?.toSafeString(unitName: String?): String {
|
||||
if (this == null || this == 0.0) return ""
|
||||
val decimalPlaces = getDecimalPlaces(unitName)
|
||||
@@ -46,6 +57,12 @@ fun Double?.toSafeDouble(unitName: String?): Double {
|
||||
return roundToDouble(decimalPlaces)
|
||||
}
|
||||
|
||||
fun Double?.toSafeDouble(decimalPlaces: Int = 2): Double {
|
||||
if (this == null || this == 0.0) return 0.0
|
||||
|
||||
return roundToDouble(decimalPlaces)
|
||||
}
|
||||
|
||||
fun Double?.toSafeFloat(unitName: String?): Float {
|
||||
if (this == null || this == 0.0) return 0f
|
||||
|
||||
@@ -53,6 +70,18 @@ fun Double?.toSafeFloat(unitName: String?): Float {
|
||||
return roundToDouble(decimalPlaces).toFloat()
|
||||
}
|
||||
|
||||
fun Double?.toSafeFloat(decimalPlaces: Int = 2): Float {
|
||||
if (this == null || this == 0.0) return 0f
|
||||
|
||||
return roundToDouble(decimalPlaces).toFloat()
|
||||
}
|
||||
|
||||
fun Float?.toSafeFloat(decimalPlaces: Int = 2): Float {
|
||||
if (this == null || this == 0f) return 0f
|
||||
|
||||
return roundToDouble(decimalPlaces).toFloat()
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过单位判断小数
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user