Groovy - Meta Programming - metaclass- change prototype


import java.text.NumberFormat;

Number.metaClass.asCurrency {
    NumberFormat nf NumberFormat.getCurrencyInstance()
    nf.format(delegate)


Number.metaClass.asCurrency Locale loc ->
    NumberFormat nf NumberFormat.getCurrencyInstance(loc)
    nf.format(delegate)
}


def amount 123456.7890
Locale.default Locale.US
assert amount.asCurrency(== '$123,456.79'
//assert amount.asCurrency(Locale.FRANCE) == "123 456,79 \u20AC"

Comments

Popular posts from this blog

தட்டு வண்டியில் காளிக்கோயில் - சிறுகதை

பிரேமாவின் பெண் குழந்தை

தீபம் பிளக்ஸ்