Giter VIP home page Giter VIP logo

currency-edittext's Introduction

Download Build Status License Android Arsenal

Currency-Edittext

A Custom EditText implementation that allows formatting of currency-based numeric inputs.

Alt text

💻 Installation

Add this in your app's build.gradle file:

dependencies {
  implementation 'me.abhinay.input:currency-edittext:1.1'
}

Or add ClapFab as a new dependency inside your pom.xml

<dependency>
  <groupId>me.abhinay.input</groupId>
  <artifactId>currency-edittext</artifactId>
  <version>1.1</version>
  <type>pom</type>
</dependency>

Implementation Sample

XML

<me.abhinay.input.CurrencyEditText
        android:id="@+id/etInput"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="Type value"
        android:inputType="number"
        android:textSize="24sp" />

Code

CurrencyEditText etInput;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    etInput = (CurrencyEditText) findViewById(R.id.etInput);
    etInput.setCurrency(Currency.USA);
    etInput.setDelimiter(false);
    etInput.setSpacing(false);
    etInput.setDecimals(true);
    //Make sure that Decimals is set as false if a custom Separator is used
    etInput.setSeparator(".");
}

Customizing

The following attributes can be manipulated:

  • Currency by specifying the country
  • Spacing between currency and value
  • Delimeter
  • Decimals
  • Thousands Separator Symbol

Currency

Specify the currency by setting the country of your choice.

etInput.Currency = Currency.MALAYSIA;

Currency can also be disabled by:

etInput.Currency = Currency.NONE;

Custom Currency/Symbol

If a custom symbol that is not included in the library is required, any string value can be used since the the Currency attribute expects a String value.

etInput.Currency = "TEST";

Which produces:

TEST 450.00

Note: Currency is set to your app's Local currency by default.

Spacing

The spacing between the currency and the value can be specified by:

etInput.Spacing = true;

Note: Spacing is false by default.

Delimeter

The delimeter attribute allows the addition of a . symbol after displaying the currency.

Rs.100

Rp.100

Note: Delimeter is false by default.

Decimals

Decimals can be turned off for the EditText using:

etInput.Decimals = false;

This outputs the following:

$100,000

Separator

The Thousands Separator can be customized as required with any custom symbol to suit the currency formats of different countries. Example: Indonesia -> 12.000.000 (Using . instead of , as the separator)

NOTE: Decimals must be set as false in order avoid conflicts in getting a clean Double or Integer output

Getting Clean Output

A Double value without Commas, Currency and Decimal places can be retrieved using:

double cleanOutput = etInput.getCleanDoubleValue();

An Integer value without Commas, Currency and Decimal places can be retrieved using:

int cleanOutput = etInput.getCleanIntValue();

currency-edittext's People

Contributors

abhinayme avatar abhisnsoft avatar gabe351 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

currency-edittext's Issues

Unknown Symbol

Hi, how can I fix this issue? Only happen on Huawei devices, I got 2 issue which is:

  1. Unknown Symbol
  2. Wrong currency formatting, for example 5,555.00 will be ¤0.0555500

java.lang.NumberFormatException: For input string: "¤0.05"
at sun.misc.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:2043)

Not working for digits more than 9

Hi, I have a problem when input number with digits is more than 9. For example: 99999999999. Instead giving me the output of Rp 99.999.999.999, the library give me output like this Rp Rp 999.999.99999. number with digits more than 9 just simply not working.

Xamarin android

Hola, ¿alguien sabe como se usaria este componente en xamarin android?

Format text error

Sometimes it shows the ¤ character and when the getCleanDoubleValue () method is used the application stops working.

Many times I have tried to recreate the exact scenario, but it seems to happen randomly.

Thanks for the excellent library and sorry for the inconvenience.

Error:

CurrencyEditText.java, line 121
java.lang.NumberFormatException: For input string: "117 ¤"

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.