Android Open Source - ccardstats Money Helper






From Project

Back to project page ccardstats.

License

The source code is released under:

GNU General Public License

If you think the Android project ccardstats listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.github.marwinxxii.ccardstats.helpers;
/*from w w  w . j  a v a 2 s.  co m*/
import java.util.Map;


public class MoneyHelper {
    
    private static Map<String, Double> exchangeRates;
    
    public static void setExchangeRates(Map<String, Double> rates) {
        exchangeRates = rates;
    }
    
    public static String formatMoney(double value, boolean isIncome) {
        String format;
        if (value < 0.01) {
            format = "%.2f";
        } else {
            format = isIncome ?"+%.2f":"-%.2f";
        }
        return String.format(format, value);
    }
    
    public static double parseCurrency(String number) {
        for (String cur:exchangeRates.keySet()) {
            if (number.indexOf(cur) != -1) {
                number = number.replace(cur, "").trim();
                return Double.parseDouble(number) * exchangeRates.get(cur);
            }
        }
        return Double.parseDouble(number.replace("rur", "").replace("rub", ""));
    }
    
    public static double parseCurrency(String value, String currency) {
        Double rate = exchangeRates.get(currency.toLowerCase().replace(".", ""));
        double result = Double.parseDouble(value);
        if (rate == null) return result;
        return result * rate;
    }
}




Java Source Code List

com.github.marwinxxii.ccardstats.Application.java
com.github.marwinxxii.ccardstats.SmsReceiver.java
com.github.marwinxxii.ccardstats.db.Card.java
com.github.marwinxxii.ccardstats.db.DBHelper.java
com.github.marwinxxii.ccardstats.gui.CardListActivity.java
com.github.marwinxxii.ccardstats.gui.GetStatsTask.java
com.github.marwinxxii.ccardstats.gui.ListActivity.java
com.github.marwinxxii.ccardstats.gui.MonthStatsActivity.java
com.github.marwinxxii.ccardstats.gui.PreferencesActivity.java
com.github.marwinxxii.ccardstats.gui.SimpleListActivity.java
com.github.marwinxxii.ccardstats.gui.TextMappingAdapter.java
com.github.marwinxxii.ccardstats.gui.YearStatsActivity.java
com.github.marwinxxii.ccardstats.helpers.DateHelper.java
com.github.marwinxxii.ccardstats.helpers.MoneyHelper.java
com.github.marwinxxii.ccardstats.notifications.NotificationReader.java
com.github.marwinxxii.ccardstats.notifications.NotificationService.java
com.github.marwinxxii.ccardstats.notifications.SberbankService.java
com.github.marwinxxii.ccardstats.notifications.SmsNotification.java
com.github.marwinxxii.ccardstats.notifications.SmsParser.java
com.github.marwinxxii.ccardstats.notifications.SmsReader.java