Thursday, September 9, 2010
Java Code For India Currency Formate
<%!
public static String inidianCurrencyFormat(String amount) {
try {
double value = Double.parseDouble(amount);
boolean isNegative = false;
if(value < 0) {
value = value * -1;
isNegative = true;
}
java.text.DecimalFormat formatter = new java.text.DecimalFormat("0.00");
String formattedValue = formatter.format(value);
String integral = formattedValue.replaceAll("\\D\\d++", "");
String fraction = formattedValue.replaceAll("\\d++\\D", "");
if(integral.length() <= 3) return formattedValue;
char lastDigitOfIntegral = integral.charAt(integral.length()-1);
integral = integral.replaceAll("\\d$", "");
integral = integral.replaceAll("(?<=.)(?=(?:\\d{2})+$)", ",")+
lastDigitOfIntegral+"."+fraction;
if(isNegative) {
integral = "- " + integral;
}
return integral;
} catch (NumberFormatException e) {
//log.error("Invalid number" + amount);
return amount;
}
}
%>
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment