IMPLEMENTATION OF NUMBERFORMAT GROOVY SCRIPT:
Initially a temporary variable gets the value of the field that needs to be formatted. Assuming the current value is in the string format, the length of the value is calculated based on the decimal.
def tempValue = c_Value //e.g. $USD 9967644.09
def currentIndex = tempValue.indexOf('.')
def currencyValue
if(currentIndex<0)
currencyValue = tempValue
else
{
currencyValue =tempValue.substring(0,currentIndex)
}
def currencyLength = currencyValue.length()
After 3 digit formatting, the obtained values are added into a list.
def temp=0
def emptyList = []
if(currencyLength%3 !=0)
temp = currencyLength%3
if(temp!=0 && temp<=currencyLength ){
emptyList.add(currencyValue.substring(0,temp))
}
else
{
emptyList.add(currencyValue.substring(0,temp+3))
temp=temp+3
}
while(temp<currencyLength)
{
emptyList.add(currencyValue.substring(temp,temp+3))
temp=temp+3
}
- Finally all the values in the list are concatenated as comma separated string and returned as desired US currency format.
String finalCurrency = ""
int i
for(i=0;i<emptyList.size();i++)
{
finalCurrency+=emptyList[i]+','
}
return "\$"+finalCurrency.substring(0,finalCurrency.length()-1) //e.g. $9,967,644
The above code is defined as a global function formatCurrency which could be referred in the text formula field as below,
def currencyValue = OptyRevenue_c
def tempValue = currencyValue.toString()
def finalCurrency=adf.util.formatCurrency(tempValue)//has the formatted value
No comments:
Post a Comment