Groovy web console

subscribe to the feed Subscribe
to this
site

Dotted price

Published 5 months ago by yisus
Actions  ➤ Edit in console Back to console Show/hide line numbers View recent scripts
    private static String getDottedPrice(String price) {        String dottedPrice = ""
        price.toString().reverse().eachWithIndex { String entry, int i ->            dottedPrice = i % 3 == 0 ? "${dottedPrice}.${entry}" : "${dottedPrice}${entry}"        }
        dottedPrice[1..dottedPrice.length() - 1].reverse()
    }

println getDottedPrice("100.0")