1

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.

Markus Weninger
  • 11,931
  • 7
  • 64
  • 137

1 Answers1

5

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.

Marko Topolnik
  • 195,646
  • 29
  • 319
  • 436