Skip to content

Instantly share code, notes, and snippets.

@ppazos
Created September 16, 2021 20:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ppazos/71dfe2ba04334f057a1aa867d672a24f to your computer and use it in GitHub Desktop.
Save ppazos/71dfe2ba04334f057a1aa867d672a24f to your computer and use it in GitHub Desktop.
BigDecimal.metaClass.round2 = {
def ctx = new java.math.MathContext(4) // doesnt work this is the total number of digits not the decimals
delegate.round(ctx)
}
def n = 2290.389649
println n.round2()
println n.setScale(2, java.math.RoundingMode.HALF_UP)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment