Skip to content

Instantly share code, notes, and snippets.

@sharish
Last active August 29, 2015 14:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sharish/0cf13e8112e1184d575b to your computer and use it in GitHub Desktop.
Save sharish/0cf13e8112e1184d575b to your computer and use it in GitHub Desktop.
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