Code Monkey home page Code Monkey logo

tradukisto's Introduction

Tradukisto

Build Status codecov Maven Central

Tradukisto is a library for Java 8+ created to convert numbers to their word representations.

The main motivation behind its creation was lack of a production-ready tool providing number conversion for Polish language. There are many individual classes, but we felt there is definitely space for something well tested and ready to use in production without copy-pasting someone else's code.

Features

  • Converts Integer to String with numerical representation support.
  • Converts Long to String with numerical representation support.
  • Converts BigDecimal to String with money representation support.

Supported languages

  • Brazilian Portuguese
  • Bulgarian
  • Czech
  • English
  • French
  • German
  • Italian
  • Kazakh
  • Latvian
  • Polish
  • Russian
  • Slovak
  • Ukrainian
  • Serbian (latin)
  • Serbian (cyrillic)
  • Turkish

Usage

Add tradukisto as dependency:

repositories {
    mavenCentral()
}

dependencies {
    compile 'pl.allegro.finance:tradukisto:1.12.0'
}

and use it:

ValueConverters intConverter = ValueConverters.ENGLISH_INTEGER;
String valueAsWords = intConverter.asWords(1_234);

assertEquals("one thousand two hundred thirty-four", valueAsWords);
LongValueConverters longConverter = LongValueConverters.ENGLISH_LONG;
String valueAsWords = converter.asWords(1_000_000_000_000_000_000);

assertEquals("one quintillion", valueAsWords);
MoneyConverters converter = MoneyConverters.ENGLISH_BANKING_MONEY_VALUE;

String moneyAsWords = converter.asWords(new BigDecimal("1234.56"));
assertEquals("one thousand two hundred thirty-four £ 56/100", moneyAsWords);

String moneyAsWordsWithCurrency = converter.asWords(new BigDecimal("1234.56", "EUR"));
assertEquals("one thousand two hundred thirty-four EUR 56/100", moneyAsWordsWithCurrency);

Tradukisto can handle only values with no more than two digits after the decimal point. Otherwise IllegalArgumentException will be thrown. For that reason you should either construct BigDecimal object based on String value as shown in example above or use setScale method to ensure that given value has appropriate precision.

License

Copyright 2015-2022 Allegro Group

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

tradukisto's People

Contributors

dorians avatar maciejlipinski avatar dilaverdemirel avatar wjur avatar bgalek avatar mkosmul avatar aleksandarni avatar fatosmorina avatar michalkuzma21 avatar blarne avatar gavrilovniki avatar aboruhen avatar thomaszangerl avatar altro3 avatar ma-go-src avatar rpanecki avatar

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.