Number format display (Indian Currency Format)
STEP 1 :-
To display Number format in Indian Currency we need java code to convert number to Indian Currency format.
In my Case, I have to format Amount and Quantity with different Decimal places.
In Amount - 2 Decimal Places
In Quantity - 3 Decimal Places
Created a Class NumberFormatClass with 2 Method getAmountFormat() and getQtyFormat() and input parameter of method is String.
getAmountFormat() returns upto 2 places of decimal with Indian Currency Format.
getQtyFormat() returns upto 3 places of decimal with Indian Currency Format.
STEP 2 :-
Create Jar of Java file.
I have created jar file NFC.jar
STEP 3 :-
Add Jar in ireport
STEP 4 :-
Create a Parameter in Report
Set Parameter Class and Default Value Expression
STEP 4 :-
Goto Field Expression
Select method getAmountFormat
Now Run your Report
In my Case, I have to format Amount and Quantity with different Decimal places.
In Amount - 2 Decimal Places
In Quantity - 3 Decimal Places
Created a Class NumberFormatClass with 2 Method getAmountFormat() and getQtyFormat() and input parameter of method is String.
getAmountFormat() returns upto 2 places of decimal with Indian Currency Format.
getQtyFormat() returns upto 3 places of decimal with Indian Currency Format.
package custommethod.pkg; public class NumberFormatClass { public NumberFormatClass() { super(); } public String getAmountFormat(String number) { if (number.equals(null) || number.equals("null")) { return null; } Boolean negative = false; String value = number; if (value.startsWith("-")) { negative = true; value = value.replace("-", ""); } String decimal = ".00"; String s[] = value.split("\\."); String integer = "0"; if (s.length > 0 && s[0].length() > 0) { integer = s[0]; } if (s.length == 2) { if (s[1].length() == 1) { decimal = "." + s[1] + "0"; } else { decimal = "." + s[1]; } } int lenght = integer.length(); if (lenght <= 3) { } if (lenght == 4) { integer = integer.substring(lenght - 4, lenght - 3) + "," + integer.substring(lenght - 3, lenght); } else if (lenght == 5) { integer = integer.substring(lenght - 5, lenght - 3) + "," + integer.substring(lenght - 3, lenght); } else if (lenght == 6) { integer = integer.substring(lenght - 6, lenght - 5) + "," + integer.substring(lenght - 5, lenght - 3) + "," + integer.substring(lenght - 3, lenght); } else if (lenght == 7) { integer = integer.substring(lenght - 7, lenght - 5) + "," + integer.substring(lenght - 5, lenght - 3) + "," + integer.substring(lenght - 3, lenght); } else if (lenght == 8) { integer = integer.substring(lenght - 8, lenght - 7) + "," + integer.substring(lenght - 7, lenght - 5) + "," + integer.substring(lenght - 5, lenght - 3) + "," + integer.substring(lenght - 3, lenght); } else if (lenght == 9) { integer = integer.substring(lenght - 9, lenght - 7) + "," + integer.substring(lenght - 7, lenght - 5) + "," + integer.substring(lenght - 5, lenght - 3) + "," + integer.substring(lenght - 3, lenght); } else if (lenght == 10) { integer = integer.substring(lenght - 10, lenght - 9) + "," + integer.substring(lenght - 9, lenght - 7) + "," + integer.substring(lenght - 7, lenght - 5) + "," + integer.substring(lenght - 5, lenght - 3) + "," + integer.substring(lenght - 3, lenght); } else if (lenght == 11) { integer = integer.substring(lenght - 11, lenght - 9) + "," + integer.substring(lenght - 9, lenght - 7) + "," + integer.substring(lenght - 7, lenght - 5) + "," + integer.substring(lenght - 5, lenght - 3) + "," + integer.substring(lenght - 3, lenght); } else if (lenght == 12) { integer = integer.substring(lenght - 12, lenght - 11) + "," + integer.substring(lenght - 11, lenght - 9) + "," + integer.substring(lenght - 9, lenght - 7) + "," + integer.substring(lenght - 7, lenght - 5) + "," + integer.substring(lenght - 5, lenght - 3) + "," + integer.substring(lenght - 3, lenght); } else if (lenght == 13) { integer = integer.substring(lenght - 13, lenght - 11) + "," + integer.substring(lenght - 11, lenght - 9) + "," + integer.substring(lenght - 9, lenght - 7) + "," + integer.substring(lenght - 7, lenght - 5) + "," + integer.substring(lenght - 5, lenght - 3) + "," + integer.substring(lenght - 3, lenght); } else if (lenght == 14) { integer = integer.substring(lenght - 14, lenght - 13) + "," + integer.substring(lenght - 13, integer.length() - 11) + "," + integer.substring(lenght - 11, lenght - 9) + "," + integer.substring(lenght - 9, lenght - 7) + "," + integer.substring(lenght - 7, lenght - 5) + "," + integer.substring(lenght - 5, lenght - 3) + "," + integer.substring(lenght - 3, lenght); } else if (lenght == 15) { integer = integer.substring(lenght - 15, lenght - 13) + "," + integer.substring(lenght - 13, integer.length() - 11) + "," + integer.substring(lenght - 11, lenght - 9) + "," + integer.substring(lenght - 9, lenght - 7) + "," + integer.substring(lenght - 7, lenght - 5) + "," + integer.substring(lenght - 5, lenght - 3) + "," + integer.substring(lenght - 3, lenght); } else if (lenght == 16) { integer = integer.substring(lenght - 16, lenght - 15) + "," + integer.substring(lenght - 15, lenght - 13) + "," + integer.substring(lenght - 13, lenght - 11) + "," + integer.substring(lenght - 11, lenght - 9) + "," + integer.substring(lenght - 9, lenght - 7) + "," + integer.substring(lenght - 7, lenght - 5) + "," + integer.substring(lenght - 5, lenght - 3) + "," + integer.substring(lenght - 3, lenght); } else if (lenght == 17) { integer = integer.substring(lenght - 17, lenght - 15) + "," + integer.substring(lenght - 15, lenght - 13) + "," + integer.substring(lenght - 13, lenght - 11) + "," + integer.substring(lenght - 11, lenght - 9) + "," + integer.substring(lenght - 9, lenght - 7) + "," + integer.substring(lenght - 7, lenght - 5) + "," + integer.substring(lenght - 5, lenght - 3) + "," + integer.substring(lenght - 3, lenght); } else if (lenght == 18) { integer = integer.substring(lenght - 18, lenght - 17) + "," + integer.substring(lenght - 17, lenght - 15) + "," + integer.substring(lenght - 15, lenght - 13) + "," + integer.substring(lenght - 13, lenght - 11) + "," + integer.substring(lenght - 11, lenght - 9) + "," + integer.substring(lenght - 9, lenght - 7) + "," + integer.substring(lenght - 7, lenght - 5) + "," + integer.substring(lenght - 5, lenght - 3) + "," + integer.substring(lenght - 3, lenght); } else if (lenght == 19) { integer = integer.substring(lenght - 19, lenght - 17) + "," + integer.substring(lenght - 17, lenght - 15) + "," + integer.substring(lenght - 15, lenght - 13) + "," + integer.substring(lenght - 13, lenght - 11) + "," + integer.substring(lenght - 11, lenght - 9) + "," + integer.substring(lenght - 9, lenght - 7) + "," + integer.substring(lenght - 7, lenght - 5) + "," + integer.substring(lenght - 5, lenght - 3) + "," + integer.substring(lenght - 3, lenght); } else if (lenght == 20) { integer = integer.substring(lenght - 20, integer.length() - 19) + "," + integer.substring(lenght - 19, lenght - 17) + "," + integer.substring(lenght - 17, lenght - 15) + "," + integer.substring(lenght - 15, lenght - 13) + "," + integer.substring(lenght - 13, lenght - 11) + "," + integer.substring(lenght - 11, lenght - 9) + "," + integer.substring(lenght - 9, lenght - 7) + "," + integer.substring(lenght - 7, lenght - 5) + "," + integer.substring(lenght - 5, lenght - 3) + "," + integer.substring(lenght - 3, lenght); } value = integer.concat(decimal); if (negative) { value = "-" + value; } return value; } public String getQtyFormat(String number) { if (number.equals(null) || number.equals("null")) { return null; } Boolean negative = false; String value = number; if (value.startsWith("-")) { negative = true; value = value.replace("-", ""); } String decimal = ".000"; String s[] = value.split("\\."); String integer = "0"; if (s.length > 0 && s[0].length() > 0) { integer = s[0]; } if (s.length == 2) { if (s[1].length() == 1) { decimal = "." + s[1] + "00"; } else if (s[1].length() == 2) { decimal = "." + s[1] + "0"; } else { decimal = "." + s[1]; } } int lenght = integer.length(); if (lenght <= 3) { } if (lenght == 4) { integer = integer.substring(lenght - 4, lenght - 3) + "," + integer.substring(lenght - 3, lenght); } else if (lenght == 5) { integer = integer.substring(lenght - 5, lenght - 3) + "," + integer.substring(lenght - 3, lenght); } else if (lenght == 6) { integer = integer.substring(lenght - 6, lenght - 5) + "," + integer.substring(lenght - 5, lenght - 3) + "," + integer.substring(lenght - 3, lenght); } else if (lenght == 7) { integer = integer.substring(lenght - 7, lenght - 5) + "," + integer.substring(lenght - 5, lenght - 3) + "," + integer.substring(lenght - 3, lenght); } else if (lenght == 8) { integer = integer.substring(lenght - 8, lenght - 7) + "," + integer.substring(lenght - 7, lenght - 5) + "," + integer.substring(lenght - 5, lenght - 3) + "," + integer.substring(lenght - 3, lenght); } else if (lenght == 9) { integer = integer.substring(lenght - 9, lenght - 7) + "," + integer.substring(lenght - 7, lenght - 5) + "," + integer.substring(lenght - 5, lenght - 3) + "," + integer.substring(lenght - 3, lenght); } else if (lenght == 10) { integer = integer.substring(lenght - 10, lenght - 9) + "," + integer.substring(lenght - 9, lenght - 7) + "," + integer.substring(lenght - 7, lenght - 5) + "," + integer.substring(lenght - 5, lenght - 3) + "," + integer.substring(lenght - 3, lenght); } else if (lenght == 11) { integer = integer.substring(lenght - 11, lenght - 9) + "," + integer.substring(lenght - 9, lenght - 7) + "," + integer.substring(lenght - 7, lenght - 5) + "," + integer.substring(lenght - 5, lenght - 3) + "," + integer.substring(lenght - 3, lenght); } else if (lenght == 12) { integer = integer.substring(lenght - 12, lenght - 11) + "," + integer.substring(lenght - 11, lenght - 9) + "," + integer.substring(lenght - 9, lenght - 7) + "," + integer.substring(lenght - 7, lenght - 5) + "," + integer.substring(lenght - 5, lenght - 3) + "," + integer.substring(lenght - 3, lenght); } else if (lenght == 13) { integer = integer.substring(lenght - 13, lenght - 11) + "," + integer.substring(lenght - 11, lenght - 9) + "," + integer.substring(lenght - 9, lenght - 7) + "," + integer.substring(lenght - 7, lenght - 5) + "," + integer.substring(lenght - 5, lenght - 3) + "," + integer.substring(lenght - 3, lenght); } else if (lenght == 14) { integer = integer.substring(lenght - 14, lenght - 13) + "," + integer.substring(lenght - 13, integer.length() - 11) + "," + integer.substring(lenght - 11, lenght - 9) + "," + integer.substring(lenght - 9, lenght - 7) + "," + integer.substring(lenght - 7, lenght - 5) + "," + integer.substring(lenght - 5, lenght - 3) + "," + integer.substring(lenght - 3, lenght); } else if (lenght == 15) { integer = integer.substring(lenght - 15, lenght - 13) + "," + integer.substring(lenght - 13, integer.length() - 11) + "," + integer.substring(lenght - 11, lenght - 9) + "," + integer.substring(lenght - 9, lenght - 7) + "," + integer.substring(lenght - 7, lenght - 5) + "," + integer.substring(lenght - 5, lenght - 3) + "," + integer.substring(lenght - 3, lenght); } else if (lenght == 16) { integer = integer.substring(lenght - 16, lenght - 15) + "," + integer.substring(lenght - 15, lenght - 13) + "," + integer.substring(lenght - 13, lenght - 11) + "," + integer.substring(lenght - 11, lenght - 9) + "," + integer.substring(lenght - 9, lenght - 7) + "," + integer.substring(lenght - 7, lenght - 5) + "," + integer.substring(lenght - 5, lenght - 3) + "," + integer.substring(lenght - 3, lenght); } else if (lenght == 17) { integer = integer.substring(lenght - 17, lenght - 15) + "," + integer.substring(lenght - 15, lenght - 13) + "," + integer.substring(lenght - 13, lenght - 11) + "," + integer.substring(lenght - 11, lenght - 9) + "," + integer.substring(lenght - 9, lenght - 7) + "," + integer.substring(lenght - 7, lenght - 5) + "," + integer.substring(lenght - 5, lenght - 3) + "," + integer.substring(lenght - 3, lenght); } else if (lenght == 18) { integer = integer.substring(lenght - 18, lenght - 17) + "," + integer.substring(lenght - 17, lenght - 15) + "," + integer.substring(lenght - 15, lenght - 13) + "," + integer.substring(lenght - 13, lenght - 11) + "," + integer.substring(lenght - 11, lenght - 9) + "," + integer.substring(lenght - 9, lenght - 7) + "," + integer.substring(lenght - 7, lenght - 5) + "," + integer.substring(lenght - 5, lenght - 3) + "," + integer.substring(lenght - 3, lenght); } else if (lenght == 19) { integer = integer.substring(lenght - 19, lenght - 17) + "," + integer.substring(lenght - 17, lenght - 15) + "," + integer.substring(lenght - 15, lenght - 13) + "," + integer.substring(lenght - 13, lenght - 11) + "," + integer.substring(lenght - 11, lenght - 9) + "," + integer.substring(lenght - 9, lenght - 7) + "," + integer.substring(lenght - 7, lenght - 5) + "," + integer.substring(lenght - 5, lenght - 3) + "," + integer.substring(lenght - 3, lenght); } else if (lenght == 20) { integer = integer.substring(lenght - 20, integer.length() - 19) + "," + integer.substring(lenght - 19, lenght - 17) + "," + integer.substring(lenght - 17, lenght - 15) + "," + integer.substring(lenght - 15, lenght - 13) + "," + integer.substring(lenght - 13, lenght - 11) + "," + integer.substring(lenght - 11, lenght - 9) + "," + integer.substring(lenght - 9, lenght - 7) + "," + integer.substring(lenght - 7, lenght - 5) + "," + integer.substring(lenght - 5, lenght - 3) + "," + integer.substring(lenght - 3, lenght); } value = integer.concat(decimal); if (negative) { value = "-" + value; } return value; } public String getFactorFormat(String number) { if (number.equals(null) || number.equals("null")) { return null; } Boolean negative = false; String value = number; if (value.startsWith("-")) { negative = true; value = value.replace("-", ""); } String decimal = ".0000"; String s[] = value.split("\\."); String integer = "0"; if (s.length > 0 && s[0].length() > 0) { integer = s[0]; } if (s.length == 2) { if (s[1].length() == 1) { decimal = "." + s[1] + "000"; } else if (s[1].length() == 2) { decimal = "." + s[1] + "00"; } else if (s[1].length() == 3) { decimal = "." + s[1] + "0"; } else { decimal = "." + s[1]; } } int lenght = integer.length(); if (lenght <= 3) { } if (lenght == 4) { integer = integer.substring(lenght - 4, lenght - 3) + "," + integer.substring(lenght - 3, lenght); } else if (lenght == 5) { integer = integer.substring(lenght - 5, lenght - 3) + "," + integer.substring(lenght - 3, lenght); } else if (lenght == 6) { integer = integer.substring(lenght - 6, lenght - 5) + "," + integer.substring(lenght - 5, lenght - 3) + "," + integer.substring(lenght - 3, lenght); } else if (lenght == 7) { integer = integer.substring(lenght - 7, lenght - 5) + "," + integer.substring(lenght - 5, lenght - 3) + "," + integer.substring(lenght - 3, lenght); } else if (lenght == 8) { integer = integer.substring(lenght - 8, lenght - 7) + "," + integer.substring(lenght - 7, lenght - 5) + "," + integer.substring(lenght - 5, lenght - 3) + "," + integer.substring(lenght - 3, lenght); } else if (lenght == 9) { integer = integer.substring(lenght - 9, lenght - 7) + "," + integer.substring(lenght - 7, lenght - 5) + "," + integer.substring(lenght - 5, lenght - 3) + "," + integer.substring(lenght - 3, lenght); } else if (lenght == 10) { integer = integer.substring(lenght - 10, lenght - 9) + "," + integer.substring(lenght - 9, lenght - 7) + "," + integer.substring(lenght - 7, lenght - 5) + "," + integer.substring(lenght - 5, lenght - 3) + "," + integer.substring(lenght - 3, lenght); } else if (lenght == 11) { integer = integer.substring(lenght - 11, lenght - 9) + "," + integer.substring(lenght - 9, lenght - 7) + "," + integer.substring(lenght - 7, lenght - 5) + "," + integer.substring(lenght - 5, lenght - 3) + "," + integer.substring(lenght - 3, lenght); } else if (lenght == 12) { integer = integer.substring(lenght - 12, lenght - 11) + "," + integer.substring(lenght - 11, lenght - 9) + "," + integer.substring(lenght - 9, lenght - 7) + "," + integer.substring(lenght - 7, lenght - 5) + "," + integer.substring(lenght - 5, lenght - 3) + "," + integer.substring(lenght - 3, lenght); } else if (lenght == 13) { integer = integer.substring(lenght - 13, lenght - 11) + "," + integer.substring(lenght - 11, lenght - 9) + "," + integer.substring(lenght - 9, lenght - 7) + "," + integer.substring(lenght - 7, lenght - 5) + "," + integer.substring(lenght - 5, lenght - 3) + "," + integer.substring(lenght - 3, lenght); } else if (lenght == 14) { integer = integer.substring(lenght - 14, lenght - 13) + "," + integer.substring(lenght - 13, integer.length() - 11) + "," + integer.substring(lenght - 11, lenght - 9) + "," + integer.substring(lenght - 9, lenght - 7) + "," + integer.substring(lenght - 7, lenght - 5) + "," + integer.substring(lenght - 5, lenght - 3) + "," + integer.substring(lenght - 3, lenght); } else if (lenght == 15) { integer = integer.substring(lenght - 15, lenght - 13) + "," + integer.substring(lenght - 13, integer.length() - 11) + "," + integer.substring(lenght - 11, lenght - 9) + "," + integer.substring(lenght - 9, lenght - 7) + "," + integer.substring(lenght - 7, lenght - 5) + "," + integer.substring(lenght - 5, lenght - 3) + "," + integer.substring(lenght - 3, lenght); } else if (lenght == 16) { integer = integer.substring(lenght - 16, lenght - 15) + "," + integer.substring(lenght - 15, lenght - 13) + "," + integer.substring(lenght - 13, lenght - 11) + "," + integer.substring(lenght - 11, lenght - 9) + "," + integer.substring(lenght - 9, lenght - 7) + "," + integer.substring(lenght - 7, lenght - 5) + "," + integer.substring(lenght - 5, lenght - 3) + "," + integer.substring(lenght - 3, lenght); } else if (lenght == 17) { integer = integer.substring(lenght - 17, lenght - 15) + "," + integer.substring(lenght - 15, lenght - 13) + "," + integer.substring(lenght - 13, lenght - 11) + "," + integer.substring(lenght - 11, lenght - 9) + "," + integer.substring(lenght - 9, lenght - 7) + "," + integer.substring(lenght - 7, lenght - 5) + "," + integer.substring(lenght - 5, lenght - 3) + "," + integer.substring(lenght - 3, lenght); } else if (lenght == 18) { integer = integer.substring(lenght - 18, lenght - 17) + "," + integer.substring(lenght - 17, lenght - 15) + "," + integer.substring(lenght - 15, lenght - 13) + "," + integer.substring(lenght - 13, lenght - 11) + "," + integer.substring(lenght - 11, lenght - 9) + "," + integer.substring(lenght - 9, lenght - 7) + "," + integer.substring(lenght - 7, lenght - 5) + "," + integer.substring(lenght - 5, lenght - 3) + "," + integer.substring(lenght - 3, lenght); } else if (lenght == 19) { integer = integer.substring(lenght - 19, lenght - 17) + "," + integer.substring(lenght - 17, lenght - 15) + "," + integer.substring(lenght - 15, lenght - 13) + "," + integer.substring(lenght - 13, lenght - 11) + "," + integer.substring(lenght - 11, lenght - 9) + "," + integer.substring(lenght - 9, lenght - 7) + "," + integer.substring(lenght - 7, lenght - 5) + "," + integer.substring(lenght - 5, lenght - 3) + "," + integer.substring(lenght - 3, lenght); } else if (lenght == 20) { integer = integer.substring(lenght - 20, integer.length() - 19) + "," + integer.substring(lenght - 19, lenght - 17) + "," + integer.substring(lenght - 17, lenght - 15) + "," + integer.substring(lenght - 15, lenght - 13) + "," + integer.substring(lenght - 13, lenght - 11) + "," + integer.substring(lenght - 11, lenght - 9) + "," + integer.substring(lenght - 9, lenght - 7) + "," + integer.substring(lenght - 7, lenght - 5) + "," + integer.substring(lenght - 5, lenght - 3) + "," + integer.substring(lenght - 3, lenght); } value = integer.concat(decimal); if (negative) { value = "-" + value; } return value; } }
STEP 2 :-
Create Jar of Java file.
I have created jar file NFC.jar
STEP 3 :-
Add Jar in ireport
STEP 4 :-
Create a Parameter in Report
Set Parameter Class and Default Value Expression
STEP 4 :-
Goto Field Expression
Select method getAmountFormat
Now Run your Report