Get string with unit¶
Quick start¶
The following are the units provided by default.
Unit | Unit Value |
---|---|
Angle | 39° |
Celsius | 36℃ |
Kmh | 2km/h |
Kilometer | 2km |
Meter | 2m |
Ms | 2m/s |
Percent | 77% |
// Get value as 12km/h
@Composable
fun UnitString(){
Text(text = "12".withUnit(Kmh()))
}
UnitStringKt.withUnit(1, new Angle());
Custom unit¶
By implementing StrUnit
you can customize the unit:
open class Percent : StrUnit {
override val unit = "%"
}
class WindSpeed implements StrUnit {
@NonNull
@Override
public String getUnit() {
return "m/s";
}
@NonNull
@Override
public String getValue(@NonNull String value) {
return value + getUnit();
}
}