public class Test { public static String inidianCurrencyFormat(double value) { DecimalFormat formatter = new 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$", ""); return integral.replaceAll("(?<=.)(?=(?:\\d{2})+$)", ",")+ lastDigitOfIntegral+"."+fraction; } public static void main(String[] args){ System.out.println(inidianCurrencyFormat(0.898)); System.out.println(inidianCurrencyFormat(890.898)); System.out.println(inidianCurrencyFormat(567890.898)); System.out.println(inidianCurrencyFormat(1234567890.898)); } }
Thursday, September 9, 2010
Core Java Programming: Indian currency format
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment