Subversion Repositories SmartDukaan

Rev

Rev 24401 | Rev 28310 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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