Rev 28310 | Rev 28533 | Go to most recent revision | View as "text/plain" | Blame | Compare with Previous | Last modification | View Log | RSS feed
package com.spice.profitmandi.common.util;import java.text.DecimalFormat;import java.text.NumberFormat;import java.time.LocalDateTime;import java.time.format.DateTimeFormatter;import java.util.Locale;public class FormattingUtils {private static Locale indianLocale = new Locale("en", "IN");private static DecimalFormat f = new DecimalFormat("##.00");private NumberFormat currencyFormat;private static DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("dd-MM-yyyy");private static DateTimeFormatter reporticoFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");private static DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("dd-MM-yyyy HH:mm");private static DateTimeFormatter ymFormatter = DateTimeFormatter.ofPattern("yyyyMM");private static DateTimeFormatter monYYYYFormatter = DateTimeFormatter.ofPattern("MMM-yyyy");public static String getYearMonth(LocalDateTime dateTime) {return dateTime.format(dateFormatter);}public static String formatYearMonth(LocalDateTime dateTime) {return dateTime.format(monYYYYFormatter);}public FormattingUtils(){currencyFormat = NumberFormat.getNumberInstance(indianLocale);currencyFormat.setMaximumFractionDigits(2);currencyFormat.setMinimumFractionDigits(2);currencyFormat.setMinimumIntegerDigits(1);}public FormattingUtils(int maximumFractionDigits){currencyFormat = NumberFormat.getNumberInstance(indianLocale);currencyFormat.setMaximumFractionDigits(maximumFractionDigits);currencyFormat.setMinimumIntegerDigits(1);}public String formatPrice(double amount){return currencyFormat.format(amount);}public static String format(LocalDateTime localDateTime){return localDateTime.format(dateTimeFormatter);}public static String formatDecimalTwoDigits(double number) {return f.format(number);}public static String formatDate(LocalDateTime dateTime) {return dateTime.format(dateFormatter);}public static String formatReporitcoDate(LocalDateTime dateTime) {if(dateTime==null) return "-";return dateTime.format(reporticoFormatter);}public static String formatShortHand(long value) {String finalval = null;if (value >= 100000 && value < 10000000) {long reminder = value / 100000;long quitonent = value % 100000;finalval = reminder + "." + quitonent;String secondval = String.valueOf(quitonent);if (secondval.length() >= 2) {secondval = secondval.substring(0, 2);finalval = reminder + "." + secondval;}return String.valueOf(finalval) + " Lacs";} else if (value >= 1000 && value < 100000) {long reminder = value / 1000;long quitonent = value % 1000;finalval = reminder + "." + quitonent;String secondval = String.valueOf(quitonent);if (secondval.length() >= 2) {secondval = secondval.substring(0, 2);finalval = reminder + "." + secondval;}return String.valueOf(finalval) + " K";} else if (value >= 10000000 && value < 1000000000) {long reminder = value / 10000000;long quitonent = value % 10000000;finalval = reminder + "." + quitonent;String secondval = String.valueOf(quitonent);if (secondval.length() >= 2) {secondval = secondval.substring(0, 2);finalval = reminder + "." + secondval;}return String.valueOf(finalval) + " Cr";}return String.valueOf(finalval);}}