Groovy web console

subscribe to the feed Subscribe
to this
site
Rounding for X-axis (via #groovywebconsole)
tweet this snippet Tweet
this
script

Rounding for X-axis

Published 3 months ago by Anonymous
Actions  ➤ Edit in console Back to console Show/hide line numbers View recent scripts
def tests = [4, 87, 1, 234, 500]
def results = []

def roundProper(x) {
    return Math.ceil(x * Math.pow(10, -Math.floor(Math.log10(x)))) / Math.pow(10, -Math.floor(Math.log10(x)))
}

tests.each { x ->
    results << roundProper(x)
}

// Print "max"
println results

def steps = []
tests.each { y ->
    steps << roundProper(Math.ceil(y/5))
}
println "Final Steps: " + steps