| 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");
|
| 28532 |
amit.gupta |
18 |
private static DateTimeFormatter ymFormatter = DateTimeFormatter.ofPattern("yyyyMM");
|
| 28536 |
amit.gupta |
19 |
private static DateTimeFormatter monYYYYFormatter = DateTimeFormatter.ofPattern("MMM, yyyy");
|
| 21543 |
ashik.ali |
20 |
|
| 28532 |
amit.gupta |
21 |
public static String getYearMonth(LocalDateTime dateTime) {
|
| 28533 |
amit.gupta |
22 |
return dateTime.format(ymFormatter);
|
| 28532 |
amit.gupta |
23 |
}
|
|
|
24 |
|
|
|
25 |
|
|
|
26 |
public static String formatYearMonth(LocalDateTime dateTime) {
|
|
|
27 |
return dateTime.format(monYYYYFormatter);
|
|
|
28 |
}
|
|
|
29 |
|
| 21543 |
ashik.ali |
30 |
public FormattingUtils(){
|
|
|
31 |
currencyFormat = NumberFormat.getNumberInstance(indianLocale);
|
|
|
32 |
currencyFormat.setMaximumFractionDigits(2);
|
|
|
33 |
currencyFormat.setMinimumFractionDigits(2);
|
|
|
34 |
currencyFormat.setMinimumIntegerDigits(1);
|
|
|
35 |
}
|
|
|
36 |
|
|
|
37 |
public FormattingUtils(int maximumFractionDigits){
|
|
|
38 |
currencyFormat = NumberFormat.getNumberInstance(indianLocale);
|
|
|
39 |
currencyFormat.setMaximumFractionDigits(maximumFractionDigits);
|
|
|
40 |
currencyFormat.setMinimumIntegerDigits(1);
|
|
|
41 |
}
|
|
|
42 |
|
|
|
43 |
public String formatPrice(double amount){
|
|
|
44 |
return currencyFormat.format(amount);
|
|
|
45 |
}
|
|
|
46 |
|
| 28310 |
amit.gupta |
47 |
public static String format(LocalDateTime localDateTime){
|
|
|
48 |
return localDateTime.format(dateTimeFormatter);
|
|
|
49 |
}
|
|
|
50 |
|
| 23556 |
amit.gupta |
51 |
public static String formatDecimalTwoDigits(double number) {
|
|
|
52 |
return f.format(number);
|
|
|
53 |
}
|
| 23532 |
amit.gupta |
54 |
public static String formatDate(LocalDateTime dateTime) {
|
| 23539 |
amit.gupta |
55 |
return dateTime.format(dateFormatter);
|
| 23532 |
amit.gupta |
56 |
}
|
|
|
57 |
|
| 23945 |
amit.gupta |
58 |
public static String formatReporitcoDate(LocalDateTime dateTime) {
|
| 24251 |
amit.gupta |
59 |
if(dateTime==null) return "-";
|
| 23945 |
amit.gupta |
60 |
return dateTime.format(reporticoFormatter);
|
|
|
61 |
}
|
| 27870 |
amit.gupta |
62 |
|
|
|
63 |
public static String formatShortHand(long value) {
|
|
|
64 |
String finalval = null;
|
|
|
65 |
|
|
|
66 |
if (value >= 100000 && value < 10000000) {
|
|
|
67 |
long reminder = value / 100000;
|
|
|
68 |
long quitonent = value % 100000;
|
|
|
69 |
finalval = reminder + "." + quitonent;
|
|
|
70 |
String secondval = String.valueOf(quitonent);
|
|
|
71 |
if (secondval.length() >= 2) {
|
|
|
72 |
secondval = secondval.substring(0, 2);
|
|
|
73 |
finalval = reminder + "." + secondval;
|
|
|
74 |
}
|
|
|
75 |
return String.valueOf(finalval) + " Lacs";
|
|
|
76 |
} else if (value >= 1000 && value < 100000) {
|
|
|
77 |
long reminder = value / 1000;
|
|
|
78 |
long quitonent = value % 1000;
|
|
|
79 |
finalval = reminder + "." + quitonent;
|
|
|
80 |
String secondval = String.valueOf(quitonent);
|
|
|
81 |
if (secondval.length() >= 2) {
|
|
|
82 |
secondval = secondval.substring(0, 2);
|
|
|
83 |
finalval = reminder + "." + secondval;
|
|
|
84 |
}
|
|
|
85 |
return String.valueOf(finalval) + " K";
|
|
|
86 |
} else if (value >= 10000000 && value < 1000000000) {
|
|
|
87 |
long reminder = value / 10000000;
|
|
|
88 |
long quitonent = value % 10000000;
|
|
|
89 |
finalval = reminder + "." + quitonent;
|
|
|
90 |
String secondval = String.valueOf(quitonent);
|
|
|
91 |
if (secondval.length() >= 2) {
|
|
|
92 |
secondval = secondval.substring(0, 2);
|
|
|
93 |
finalval = reminder + "." + secondval;
|
|
|
94 |
}
|
|
|
95 |
return String.valueOf(finalval) + " Cr";
|
|
|
96 |
}
|
|
|
97 |
return String.valueOf(finalval);
|
|
|
98 |
|
|
|
99 |
}
|
| 21543 |
ashik.ali |
100 |
}
|