Skip to content

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%

Version 0.5.1

// Get value as 12km/h
@Composable
fun UnitString(){
    Text(text = "12".withUnit(Kmh()))
}
UnitStringKt.withUnit(1, new Angle());

Custom unit

Version 0.5.2

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();
    }
}

Sample code

Sample code