Last active
August 29, 2015 14:27
-
-
Save sharish/0cf13e8112e1184d575b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public String getFormattedPrice(Resources resources) { | |
final String LAKH = "L"; | |
final String CRORE = "C"; | |
double value = getPrice(); | |
String rupees = resources.getString(R.string.rupee); | |
if (value >= 100) { | |
value = value / 100; | |
return rupees + formatToStringDoublePrecision(value) + " " + CRORE; | |
} else { | |
return rupees + formatToStringDoublePrecision(value) + " " + LAKH; | |
} | |
} | |
public static String formatToStringDoublePrecision(double value) { | |
String formatted = String.format("%.2f",value); | |
if(formatted.endsWith(".00")) { | |
return String.valueOf(Integer.parseInt(formatted)); | |
} | |
return formatted; | |
} | |
<string name="rupee">Rs. </string> | |
<string name="rupee">\u20B9 </string> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment