Kotlin - Make extension function accessible in whole project

700 views Asked by At

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.

1

There are 1 answers

2
Marko Topolnik On

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.