I have this extension function in a class:
fun Double.round2() : Double {
return Math.round((this) * 100.0) / 100.0
}
I want to reuse this function in another class without the need to duplicate the code. How can I do it? Thank you.
I have this extension function in a class:
fun Double.round2() : Double {
return Math.round((this) * 100.0) / 100.0
}
I want to reuse this function in another class without the need to duplicate the code. How can I do it? Thank you.
Your function should be defined at the top level. It will be automatically visible anywhere from the same package, and from other packages with the help of an import
statement.