Code Monkey home page Code Monkey logo

samyeak / numericwordsconversion Goto Github PK

View Code? Open in Web Editor NEW
14.0 2.0 7.0 105 KB

Numeric Words Conversion is a C# library for converting numeric into words. The goal is to create a simple customizable library which can easily be used to convert any numbers or currencies to words.

Home Page: https://samyeak.github.io/NumericWordsConversion/

License: GNU General Public License v3.0

C# 100.00%
unicode numbertowords number-to-words number-to-text nepali-words hindi-words currency-to-words number-to-unicode number-in-words numeric-words-conversion

numericwordsconversion's Introduction

Numeric Words Conversion

Build Unit Tests FOSSA Status

Numeric Words Conversion is a C# library for converting numeric into words. The goal is to create a simple customizable library which can easily be used to convert any numbers or currencies to words.

Usage

For Numeric

decimal amount = 100000.12;
NumericWordsConverter converter = new NumericWordsConverter();
string words = converter.ToWords(amount)
//OR SIMPLY
string words = amount.ToNumericWords();
//Outputs: One hundred thousand point one two
  • Supports Multiple Numeral Systems with multiple output formats
    • International English //Eg: One hundred thousand
    • Nepali and Hindi Supports multiple output formats
      • Output Format : English Eg: 100000.1 outputs One lakh point one
      • Output Format : Unicode Eg: 100000.1 outputs एक लाख दशमलव एक
      • Output Format : Devnagari Eg: 100000.1 outputs Ps nfv bzdnj Ps //Makes sense in Devnagari fonts

For Currency

Supports Nepali, Hindi and International currency system out of the box. By default, uses International currency system.

decimal amount = 100000.12;
CurrencyWordsConverter converter = new CurrencyWordsConverter();
string words = converter.ToWords(amount)
//OR SIMPLY
string words = amount.ToCurrencyWords();
//Outputs: One hundred thousand dollar and twelve cents only

And you can customize it as you like by passing the options parameter

CurrencyWordsConverter converter = new CurrencyWordsConverter(new CurrencyWordsConversionOptions()
            {
                Culture = Culture.Nepali,
                OutputFormat = OutputFormat.English
            });
string words = converter.ToWords(100000.12M);
//Outputs: One lakh rupees and twelve paisa only

You can even specify your own currency units and fully customize it your own way.

CurrencyWordsConverter converter = new CurrencyWordsConverter(new CurrencyWordsConversionOptions()
            {
                Culture = Culture.International,
                OutputFormat = OutputFormat.English,
                CurrencyUnitSeparator = string.Empty,
                CurrencyUnit = "pound",
                SubCurrencyUnit = "pence",
                EndOfWordsMarker = ""
            });
string words = converter.ToWords(00000.12M);
//Outputs: One hundred thousand pound twelve pence

Need single conversion options through out the application? You can override the default options as desired. Just use the following code in startup file of the project

NumericWordsConfiguration.ConfigureConversionDefaults(options =>
            {
            //For Numeric Words Conversion
                options.SetDefaultNumericWordsOptions(new NumericWordsConversionOptions
                {
                    Culture = Culture.International,
                    DecimalSeparator = "dot",
                    DecimalPlaces = 2
                });
            });
            //For Currency Words Conversion
                options.SetDefaultCurrencyWordsOptions(new CurrencyWordsConversionOptions
                {
                    Culture = Culture.Nepali,
                    OutputFormat = OutputFormat.English,
                    CurrencyUnitSeparator = "and",
                    CurrencyUnit = "rupee",
                    CurrencyNotationType = NotationType.Prefix,
                    SubCurrencyUnit = "paisa",
                    EndOfWordsMarker = "and"
                });

And simply use the extension method anywhere in the application, as

decimal amount = 100000.01M;
amount.ToNumericWords(); //Outputs: One hundred thousand dot zero one.
amount.ToCurrencyWords(); //Outputs: Rupees one lakh and one paisa.

License

Under GNU GENERAL PUBLIC LICENSE V3

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.