mirror of
https://github.com/CatimaLoyalty/Android.git
synced 2026-01-28 08:48:31 -05:00
Initial balance support
This commit is contained in:
@@ -6,9 +6,14 @@ import android.content.Intent;
|
||||
import android.graphics.Color;
|
||||
import android.util.Log;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.text.NumberFormat;
|
||||
import java.text.ParseException;
|
||||
import java.util.Calendar;
|
||||
import java.util.Currency;
|
||||
import java.util.Date;
|
||||
import java.util.GregorianCalendar;
|
||||
import java.util.Locale;
|
||||
|
||||
import androidx.core.graphics.ColorUtils;
|
||||
|
||||
@@ -77,4 +82,41 @@ public class Utils {
|
||||
|
||||
return expiryDate.before(date.getTime());
|
||||
}
|
||||
|
||||
static public String formatBalance(BigDecimal value, Currency currency) {
|
||||
NumberFormat numberFormat = NumberFormat.getInstance();
|
||||
|
||||
if (currency == null) {
|
||||
numberFormat.setMaximumFractionDigits(0);
|
||||
return numberFormat.format(value);
|
||||
}
|
||||
|
||||
NumberFormat currencyFormat = NumberFormat.getCurrencyInstance();
|
||||
currencyFormat.setCurrency(currency);
|
||||
|
||||
return currencyFormat.format(value);
|
||||
}
|
||||
|
||||
static public String formatBalanceWithoutCurrencySymbol(BigDecimal value, Currency currency) {
|
||||
NumberFormat numberFormat = NumberFormat.getInstance();
|
||||
|
||||
if (currency == null) {
|
||||
numberFormat.setMaximumFractionDigits(0);
|
||||
return numberFormat.format(value);
|
||||
}
|
||||
|
||||
numberFormat.setMinimumFractionDigits(currency.getDefaultFractionDigits());
|
||||
numberFormat.setMaximumFractionDigits(currency.getDefaultFractionDigits());
|
||||
|
||||
return numberFormat.format(value);
|
||||
}
|
||||
|
||||
static public BigDecimal parseCurrencyInUserLocale(String value) throws ParseException, NumberFormatException {
|
||||
// BigDecimal only likes to parse in US locale
|
||||
// So we have to translate whatever the input was to US locale
|
||||
NumberFormat numberInputFormat = NumberFormat.getNumberInstance();
|
||||
NumberFormat numberToBigDecimalFormat = NumberFormat.getNumberInstance(Locale.US);
|
||||
|
||||
return new BigDecimal(numberToBigDecimalFormat.format(numberInputFormat.parse(value)));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user