| 27870 |
amit.gupta |
1 |
|
| 21543 |
ashik.ali |
2 |
package com.spice.profitmandi.common.util;
|
|
|
3 |
|
| 23556 |
amit.gupta |
4 |
import java.text.DecimalFormat;
|
| 21543 |
ashik.ali |
5 |
import java.text.NumberFormat;
|
| 23532 |
amit.gupta |
6 |
import java.time.LocalDateTime;
|
|
|
7 |
import java.time.format.DateTimeFormatter;
|
| 21543 |
ashik.ali |
8 |
import java.util.Locale;
|
|
|
9 |
|
|
|
10 |
public class FormattingUtils {
|
|
|
11 |
|
|
|
12 |
private static Locale indianLocale = new Locale("en", "IN");
|
| 23556 |
amit.gupta |
13 |
private static DecimalFormat f = new DecimalFormat("##.00");
|
|
|
14 |
private NumberFormat currencyFormat;
|
| 24401 |
amit.gupta |
15 |
private static DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("dd-MM-yyyy");
|
|
|
16 |
private static DateTimeFormatter reporticoFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
| 28310 |
amit.gupta |
17 |
private static DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("dd-MM-yyyy HH:mm");
|
| 21543 |
ashik.ali |
18 |
|
|
|
19 |
public FormattingUtils(){
|
|
|
20 |
currencyFormat = NumberFormat.getNumberInstance(indianLocale);
|
|
|
21 |
currencyFormat.setMaximumFractionDigits(2);
|
|
|
22 |
currencyFormat.setMinimumFractionDigits(2);
|
|
|
23 |
currencyFormat.setMinimumIntegerDigits(1);
|
|
|
24 |
}
|
|
|
25 |
|
|
|
26 |
public FormattingUtils(int maximumFractionDigits){
|
|
|
27 |
currencyFormat = NumberFormat.getNumberInstance(indianLocale);
|
|
|
28 |
currencyFormat.setMaximumFractionDigits(maximumFractionDigits);
|
|
|
29 |
currencyFormat.setMinimumIntegerDigits(1);
|
|
|
30 |
}
|
|
|
31 |
|
|
|
32 |
public String formatPrice(double amount){
|
|
|
33 |
return currencyFormat.format(amount);
|
|
|
34 |
}
|
|
|
35 |
|
| 28310 |
amit.gupta |
36 |
public static String format(LocalDateTime localDateTime){
|
|
|
37 |
return localDateTime.format(dateTimeFormatter);
|
|
|
38 |
}
|
|
|
39 |
|
| 23556 |
amit.gupta |
40 |
public static String formatDecimalTwoDigits(double number) {
|
|
|
41 |
return f.format(number);
|
|
|
42 |
}
|
| 23532 |
amit.gupta |
43 |
public static String formatDate(LocalDateTime dateTime) {
|
| 23539 |
amit.gupta |
44 |
return dateTime.format(dateFormatter);
|
| 23532 |
amit.gupta |
45 |
}
|
|
|
46 |
|
| 23945 |
amit.gupta |
47 |
public static String formatReporitcoDate(LocalDateTime dateTime) {
|
| 24251 |
amit.gupta |
48 |
if(dateTime==null) return "-";
|
| 23945 |
amit.gupta |
49 |
return dateTime.format(reporticoFormatter);
|
|
|
50 |
}
|
| 27870 |
amit.gupta |
51 |
|
|
|
52 |
public static String formatShortHand(long value) {
|
|
|
53 |
String finalval = null;
|
|
|
54 |
|
|
|
55 |
if (value >= 100000 && value < 10000000) {
|
|
|
56 |
long reminder = value / 100000;
|
|
|
57 |
long quitonent = value % 100000;
|
|
|
58 |
finalval = reminder + "." + quitonent;
|
|
|
59 |
String secondval = String.valueOf(quitonent);
|
|
|
60 |
if (secondval.length() >= 2) {
|
|
|
61 |
secondval = secondval.substring(0, 2);
|
|
|
62 |
finalval = reminder + "." + secondval;
|
|
|
63 |
}
|
|
|
64 |
return String.valueOf(finalval) + " Lacs";
|
|
|
65 |
} else if (value >= 1000 && value < 100000) {
|
|
|
66 |
long reminder = value / 1000;
|
|
|
67 |
long quitonent = value % 1000;
|
|
|
68 |
finalval = reminder + "." + quitonent;
|
|
|
69 |
String secondval = String.valueOf(quitonent);
|
|
|
70 |
if (secondval.length() >= 2) {
|
|
|
71 |
secondval = secondval.substring(0, 2);
|
|
|
72 |
finalval = reminder + "." + secondval;
|
|
|
73 |
}
|
|
|
74 |
return String.valueOf(finalval) + " K";
|
|
|
75 |
} else if (value >= 10000000 && value < 1000000000) {
|
|
|
76 |
long reminder = value / 10000000;
|
|
|
77 |
long quitonent = value % 10000000;
|
|
|
78 |
finalval = reminder + "." + quitonent;
|
|
|
79 |
String secondval = String.valueOf(quitonent);
|
|
|
80 |
if (secondval.length() >= 2) {
|
|
|
81 |
secondval = secondval.substring(0, 2);
|
|
|
82 |
finalval = reminder + "." + secondval;
|
|
|
83 |
}
|
|
|
84 |
return String.valueOf(finalval) + " Cr";
|
|
|
85 |
}
|
|
|
86 |
return String.valueOf(finalval);
|
|
|
87 |
|
|
|
88 |
}
|
| 21543 |
ashik.ali |
89 |
}
|