Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8372455
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T14:26:11+00:00 2026-06-09T14:26:11+00:00

Hello Friends I am using the following code to show the amount entered in

  • 0

Hello Friends I am using the following code to show the amount entered in form of currency.

public void onTextChanged(CharSequence s, int start, int before, int count) {
            if(!s.toString().matches("^\\$(\\d{1,3}(\\,\\d{3})*|(\\d+))(\\.\\d{2})?$"))
            {
                String userInput= ""+s.toString().replaceAll("[^\\d]", "");
                StringBuilder cashAmountBuilder = new StringBuilder(userInput);

                while (cashAmountBuilder.length() > 3 && cashAmountBuilder.charAt(0) == '0') {
                    cashAmountBuilder.deleteCharAt(0);
                }
                while (cashAmountBuilder.length() < 3) {
                    cashAmountBuilder.insert(0, '0');
                }
                cashAmountBuilder.insert(cashAmountBuilder.length()-2, '.');
                cashAmountBuilder.insert(0, '$');


                editAmount.setText(cashAmountBuilder.toString());
                editAmount.setTextKeepState(cashAmountBuilder.toString());
                Selection.setSelection(editAmount.getText(), cashAmountBuilder.toString().length());
            }
        }

The issue the symbol has been prefixed with “$” I either want that to be replaced by new INR symbol or blank. I have tried replacing cashAmountBuilder.insert(0, '$'); patch of code with blank it gives me compiler error.Please help me in same.
Thanks,

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T14:26:13+00:00Added an answer on June 9, 2026 at 2:26 pm

    Guys found the solution for this one.Would like to share the same with you all.

    editAmount=(EditText)findViewById(R.id.editTextPaymentAmount);
            mlocListener = new MyLocationListener();
            mlocManager.requestLocationUpdates( LocationManager.NETWORK_PROVIDER, 0, 0, mlocListener);
            editAmount.setRawInputType(Configuration.KEYBOARD_12KEY);
            editAmount.addTextChangedListener(new TextWatcher(){
                    public void afterTextChanged(Editable s) {
    
                    }
                    public void beforeTextChanged(CharSequence s, int start, int count, int after){}
                    public void onTextChanged(CharSequence s, int start, int before, int count) {
                        if(!s.toString().equals(current)){
                            editAmount.removeTextChangedListener((TextWatcher) this);
                    //   String replaceable = String.format("[%s,.]", NumberFormat.getCurrencyInstance().getCurrency().getSymbol()); 
                     //      String cleanString = s.toString().replaceAll(replaceable, "");
                       String cleanString = s.toString().replaceAll("[$,.]", "");
                     //  String cleanString = s.toString().  replaceAll("[^\\d]", "");
                           BigDecimal parsed = new BigDecimal(cleanString).setScale(2,BigDecimal.ROUND_FLOOR).divide(new BigDecimal(100),BigDecimal.ROUND_FLOOR);                
                           String formato = NumberFormat.getCurrencyInstance().format(parsed);
        System.out.println(formato);
                           current = formato;
                           String newSt=formato.substring(1);
    
                           editAmount.setText(newSt);
                           editAmount.setSelection(newSt.length());
    
                           editAmount.addTextChangedListener((TextWatcher) this);
                        }
                    }
                }); 
        }
    
    public void priceClick(View view) {
            editAmount.addTextChangedListener(new TextWatcher(){
                DecimalFormat dec = new DecimalFormat("0.00");
                private String current = "";
                public void afterTextChanged(Editable arg0) {
                }
    
                public void beforeTextChanged(CharSequence s, int start,
                        int count, int after) {
                }
    
                public void onTextChanged(CharSequence s, int start, int before, int count) {
                    if(!s.toString().equals(current)){
                        editAmount.removeTextChangedListener((TextWatcher) this);
    
                       String cleanString = s.toString().replaceAll("[$,.]", "");
    
                       BigDecimal parsed = new BigDecimal(cleanString).setScale(2,BigDecimal.ROUND_FLOOR).divide(new BigDecimal(100),BigDecimal.ROUND_FLOOR);                
                       String formato = NumberFormat.getCurrencyInstance().format(parsed);
    
                       current = formato;
                       editAmount.setText(formato);
                       editAmount.setSelection(formato.length());
    
                       editAmount.addTextChangedListener((TextWatcher) this);
                    }
                }
            });
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello friends I am using the following code in my my project. PERMISSIONS: <uses-permission
Hello friends I am using the following code in my my project. PERMISSIONS: <uses-permission
Hello friends I am using this code in my view.. Using this code I
Hello friends i need to get user information from facebook i am using code
friends, i am using following code to write Serializable object to external storage. it
Possible Duplicate: submit a form using jquery Hello friends How can I submit a
Hello friends following is my code HTML <ul class=menu-item> <li>item</li> <li>item</li> <li>item</li> </ul> CSS
Hello Friends i am using Media controler in my code and i am including
Hello friends i need a book/ tutorials for rails without using scoffold. All the
Hello friends i am running code given below which contains the setLogTimeEntery function and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.