Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
RupeeTextView . Which Prefixes ₹ symbol and adds commas separated amount value
import android.content.Context;
import android.util.AttributeSet;
import android.widget.TextView;
import com.billion.grow.logger.Log;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.util.Locale;
* Created by john on 7/7/16.
public class RupeeTextView extends TextView {
Context context;
public RupeeTextView(Context context) {
this.context = context;
public RupeeTextView(Context context, AttributeSet attrs) {
super(context, attrs);
this.context = context;
public RupeeTextView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
this.context = context;
public void setText(CharSequence text, BufferType type) {
String formatedString = null;
try {
// The comma in the format specifier does the trick
DecimalFormat formatter = (DecimalFormat) NumberFormat.getInstance(Locale.US);
formatedString = String.format("₹" + formatter.format(Double.parseDouble(text.toString()))); // adds rupee symbol and thousand seperater
} catch (NumberFormatException e) {
Log.d("Rupee TextView NumberFormatException");
super.setText(formatedString, type);
Copy link

saurabh-dk commented Jun 1, 2018

Thanks. Still works in API 27.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment