mirror of
https://github.com/Myzel394/NumberHub.git
synced 2025-06-18 16:25:27 +02:00
Fix foot precision
This commit is contained in:
parent
dba9fd713a
commit
087ba19b1f
@ -19,6 +19,6 @@
|
|||||||
package com.sadellie.unitto.core.base
|
package com.sadellie.unitto.core.base
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Current maximum scale that will be used in app. Used in various place in code
|
* Current maximum scale that will be used in app. Used in various places in code.
|
||||||
*/
|
*/
|
||||||
const val MAX_PRECISION: Int = 1_000
|
const val MAX_PRECISION: Int = 1_000
|
||||||
|
@ -19,10 +19,10 @@
|
|||||||
package com.sadellie.unitto.data.converter.collections
|
package com.sadellie.unitto.data.converter.collections
|
||||||
|
|
||||||
import com.sadellie.unitto.core.base.R
|
import com.sadellie.unitto.core.base.R
|
||||||
|
import com.sadellie.unitto.data.converter.UnitID
|
||||||
import com.sadellie.unitto.data.model.UnitGroup
|
import com.sadellie.unitto.data.model.UnitGroup
|
||||||
import com.sadellie.unitto.data.model.unit.AbstractUnit
|
import com.sadellie.unitto.data.model.unit.AbstractUnit
|
||||||
import com.sadellie.unitto.data.model.unit.NormalUnit
|
import com.sadellie.unitto.data.model.unit.NormalUnit
|
||||||
import com.sadellie.unitto.data.converter.UnitID
|
|
||||||
import java.math.BigDecimal
|
import java.math.BigDecimal
|
||||||
|
|
||||||
internal val lengthCollection: List<AbstractUnit> by lazy {
|
internal val lengthCollection: List<AbstractUnit> by lazy {
|
||||||
@ -37,7 +37,7 @@ internal val lengthCollection: List<AbstractUnit> by lazy {
|
|||||||
NormalUnit(UnitID.kilometer, BigDecimal.valueOf(1.0E+21), UnitGroup.LENGTH, R.string.unit_kilometer, R.string.unit_kilometer_short),
|
NormalUnit(UnitID.kilometer, BigDecimal.valueOf(1.0E+21), UnitGroup.LENGTH, R.string.unit_kilometer, R.string.unit_kilometer_short),
|
||||||
NormalUnit(UnitID.nautical_mile, BigDecimal.valueOf(1.852E+21), UnitGroup.LENGTH, R.string.unit_nautical_mile, R.string.unit_nautical_mile_short),
|
NormalUnit(UnitID.nautical_mile, BigDecimal.valueOf(1.852E+21), UnitGroup.LENGTH, R.string.unit_nautical_mile, R.string.unit_nautical_mile_short),
|
||||||
NormalUnit(UnitID.inch, BigDecimal.valueOf(25_400_000_000_000_000), UnitGroup.LENGTH, R.string.unit_inch, R.string.unit_inch_short),
|
NormalUnit(UnitID.inch, BigDecimal.valueOf(25_400_000_000_000_000), UnitGroup.LENGTH, R.string.unit_inch, R.string.unit_inch_short),
|
||||||
NormalUnit(UnitID.foot, BigDecimal.valueOf(304_800_000_000_002_200), UnitGroup.LENGTH, R.string.unit_foot, R.string.unit_foot_short),
|
NormalUnit(UnitID.foot, BigDecimal.valueOf(304_800_000_000_000_000), UnitGroup.LENGTH, R.string.unit_foot, R.string.unit_foot_short),
|
||||||
NormalUnit(UnitID.yard, BigDecimal.valueOf(914_400_000_000_006_400), UnitGroup.LENGTH, R.string.unit_yard, R.string.unit_yard_short),
|
NormalUnit(UnitID.yard, BigDecimal.valueOf(914_400_000_000_006_400), UnitGroup.LENGTH, R.string.unit_yard, R.string.unit_yard_short),
|
||||||
NormalUnit(UnitID.mile, BigDecimal.valueOf(1_609_344_000_000_010_500_000.0), UnitGroup.LENGTH, R.string.unit_mile, R.string.unit_mile_short),
|
NormalUnit(UnitID.mile, BigDecimal.valueOf(1_609_344_000_000_010_500_000.0), UnitGroup.LENGTH, R.string.unit_mile, R.string.unit_mile_short),
|
||||||
NormalUnit(UnitID.light_year, BigDecimal.valueOf(9.460730472E+33), UnitGroup.LENGTH, R.string.unit_light_year, R.string.unit_light_year_short),
|
NormalUnit(UnitID.light_year, BigDecimal.valueOf(9.460730472E+33), UnitGroup.LENGTH, R.string.unit_light_year, R.string.unit_light_year_short),
|
||||||
|
@ -216,10 +216,10 @@ class AllUnitsTest {
|
|||||||
foot.checkWith(inch, "100", "1200")
|
foot.checkWith(inch, "100", "1200")
|
||||||
yard.checkWith(foot, "100", "300")
|
yard.checkWith(foot, "100", "300")
|
||||||
mile.checkWith(foot, "100", "528000")
|
mile.checkWith(foot, "100", "528000")
|
||||||
light_year.checkWith(foot, "0.0000001", "3103914196.85037")
|
light_year.checkWith(foot, "0.0000001", "3103914196.85039")
|
||||||
parsec.checkWith(foot, "0.00000001", "1012361411.25044")
|
parsec.checkWith(foot, "0.00000001", "1012361411.25045")
|
||||||
kiloparsec.checkWith(foot, "0.00000000001", "1012361411.25044")
|
kiloparsec.checkWith(foot, "0.00000000001", "1012361411.25045")
|
||||||
megaparsec.checkWith(foot, "0.00000000000001", "1012361411.25044")
|
megaparsec.checkWith(foot, "0.00000000000001", "1012361411.25045")
|
||||||
mercury_equatorial_radius.checkWith(kilometer, "1", "2439.7")
|
mercury_equatorial_radius.checkWith(kilometer, "1", "2439.7")
|
||||||
venus_equatorial_radius.checkWith(kilometer, "1", "6051.8")
|
venus_equatorial_radius.checkWith(kilometer, "1", "6051.8")
|
||||||
earth_equatorial_radius.checkWith(kilometer, "1", "6371")
|
earth_equatorial_radius.checkWith(kilometer, "1", "6371")
|
||||||
|
@ -95,7 +95,10 @@ internal sealed class ConverterResult {
|
|||||||
data object Error : ConverterResult()
|
data object Error : ConverterResult()
|
||||||
}
|
}
|
||||||
|
|
||||||
internal fun ConverterResult.Time.format(mContext: Context, formatterSymbols: FormatterSymbols): String {
|
internal fun ConverterResult.Time.format(
|
||||||
|
mContext: Context,
|
||||||
|
formatterSymbols: FormatterSymbols
|
||||||
|
): String {
|
||||||
val result = mutableListOf<String>()
|
val result = mutableListOf<String>()
|
||||||
|
|
||||||
if (day.isGreaterThan(BigDecimal.ZERO)) {
|
if (day.isGreaterThan(BigDecimal.ZERO)) {
|
||||||
|
@ -451,14 +451,6 @@ internal class ConverterViewModel @Inject constructor(
|
|||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
return@launch
|
return@launch
|
||||||
}
|
}
|
||||||
val calculated2 = try {
|
|
||||||
Expression(input2.text.ifEmpty { Token.Digit._0 }).calculate()
|
|
||||||
} catch (e: ExpressionException.DivideByZero) {
|
|
||||||
_calculation.update { null }
|
|
||||||
return@launch
|
|
||||||
} catch (e: Exception) {
|
|
||||||
return@launch
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update calculation
|
// Update calculation
|
||||||
_calculation.update { if (input1.text.isExpression()) calculated1 else null }
|
_calculation.update { if (input1.text.isExpression()) calculated1 else null }
|
||||||
@ -469,6 +461,14 @@ internal class ConverterViewModel @Inject constructor(
|
|||||||
if (footInchInput) {
|
if (footInchInput) {
|
||||||
// Converted from second text field too
|
// Converted from second text field too
|
||||||
val inches = unitsRepo.getById(UnitID.inch) as DefaultUnit
|
val inches = unitsRepo.getById(UnitID.inch) as DefaultUnit
|
||||||
|
val calculated2 = try {
|
||||||
|
Expression(input2.text.ifEmpty { Token.Digit._0 }).calculate()
|
||||||
|
} catch (e: ExpressionException.DivideByZero) {
|
||||||
|
_calculation.update { null }
|
||||||
|
return@launch
|
||||||
|
} catch (e: Exception) {
|
||||||
|
return@launch
|
||||||
|
}
|
||||||
conversion += inches.convert(unitTo, calculated2)
|
conversion += inches.convert(unitTo, calculated2)
|
||||||
}
|
}
|
||||||
when {
|
when {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user