Back to project page ccardstats.
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.
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; } }