Skip to content

Instantly share code, notes, and snippets.

@shakir915
Last active April 27, 2023 11:04
Show Gist options
  • Save shakir915/853a1af16ad579d0c48223c536ecf57e to your computer and use it in GitHub Desktop.
Save shakir915/853a1af16ad579d0c48223c536ecf57e to your computer and use it in GitHub Desktop.
trim end zeros
import java.util.*
var array= arrayOf(
1.00,
1.01,
1.11,
1.10,
1.00111,
1.01111,
1.11111,
1.10111,
1.toDouble(),
)
array.forEach {
println(
String.format(Locale.ENGLISH,"%.2f",it).trimEnd('0').trimEnd('.')
)
}
@shakir915
Copy link
Author

1
1.01
1.11
1.1
1
1.01
1.11
1.1
1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment