| 7263 |
anupam.sin |
1 |
package in.shop2020.serving.utils;
|
|
|
2 |
|
|
|
3 |
import in.shop2020.model.v1.user.Cart;
|
|
|
4 |
import in.shop2020.thrift.clients.UserClient;
|
|
|
5 |
|
|
|
6 |
import java.text.NumberFormat;
|
|
|
7 |
import java.util.Locale;
|
|
|
8 |
|
|
|
9 |
public class FormattingUtils {
|
|
|
10 |
|
|
|
11 |
private static Locale indianLocale = new Locale("en", "IN");
|
|
|
12 |
|
|
|
13 |
private NumberFormat currencyFormat;
|
|
|
14 |
|
|
|
15 |
public FormattingUtils(){
|
|
|
16 |
currencyFormat = NumberFormat.getNumberInstance(indianLocale);
|
|
|
17 |
currencyFormat.setMaximumFractionDigits(2);
|
|
|
18 |
currencyFormat.setMinimumFractionDigits(2);
|
|
|
19 |
currencyFormat.setMinimumIntegerDigits(1);
|
|
|
20 |
}
|
|
|
21 |
|
|
|
22 |
public FormattingUtils(int maximumFractionDigits){
|
|
|
23 |
currencyFormat = NumberFormat.getNumberInstance(indianLocale);
|
|
|
24 |
currencyFormat.setMaximumFractionDigits(maximumFractionDigits);
|
|
|
25 |
currencyFormat.setMinimumIntegerDigits(1);
|
|
|
26 |
}
|
|
|
27 |
|
|
|
28 |
public String formatPrice(double amount){
|
|
|
29 |
return currencyFormat.format(amount);
|
|
|
30 |
}
|
|
|
31 |
|
|
|
32 |
public static void main(String[] args) throws Exception{
|
|
|
33 |
FormattingUtils formattingUtils = new FormattingUtils();
|
|
|
34 |
UserClient client = new UserClient();
|
|
|
35 |
Cart cart = client.getClient().getCart(93439);
|
|
|
36 |
double amount = cart.getTotalPrice();
|
|
|
37 |
System.out.println(amount);
|
|
|
38 |
System.out.println(formattingUtils.formatPrice(amount));
|
|
|
39 |
}
|
|
|
40 |
}
|