Giter Club home page Giter Club logo

numbertotext's Introduction

number to text converter

This NodeJs library enables you to create spoken format for numbers that represent an amount in countries currency .

install

using npm :

$ npm i num-to-txt --save

Usage

const Amount = require("num-to-txt");
const amount = new Amount(10239876); 
// defualt language set to "EN"
// you can change it by passing as second parameter like this :
const amountWithCountry = new Amount(10239876, "Fa"); 

Grouping Digits

To group digits by three, use

// The settings are optional, 
// you can pass it as object
const withDigitGrouping = amount.digitGrouped(); // returns 10,239,876

options

  • amount
  • groupDigitBy || default value set to 3, means divide number three digit, three digit
  • numbersInEnglishCharcters || defult value set to false, it means your number is shown as entered Country if you want to show in english charchers set it to true
  • decimalCount || defult value set to 0, it means if yor number is float it rounds up your number and show that without any decimals, if you want to see number with decimal, set the decimal count
  • comma || defult value set to ",", it means you get numbers like this 12,555

for Ex :

// language = "FA"
const withDigitGrouping = amount.digitGrouped({ comma : "،" }); // returns ۱۰،۲۳۹،۸۷۶
const withDigitGrouping = amount.digitGrouped({ numbersInEnglishCharcters : true }); // returns 10,239,876

or

const withDigitGrouping = amount.digitGrouped({ groupDigitBy: 2 }); // returns 10,23,98,76

Convert To Text

To display spoken format, use

/*
** language = "FA"
** The settings are optional, 
** you can pass it as object
*/
const textFormat = amount.toText(); // returns ده میلیون و دویست و سی و نه هزار و هشتصد و هفتاد و شش

options

  • withDecimals || default value is false, if you want to convert float part to text put it to true
  • badge
  • secondBadge || it works if you set withDecimals to true
  • seprator || it works if you set withDecimals to true

To display spoken format in Rials (IRR), use

const tomanFormat = amount.farsiFormatToman({ badge: "ریال" }); // returns ده میلیون و دویست و سی و نه هزار و هشتصد و هفتاد و شش ریال

contribute

add your language

1 - create a folder named YOUR-LANGUGE inside the numberToString folder

2 - look at the persian folder, inside the numberToString folder

3 - fill your folder like that

4 - edit and add your files to index.js inside the numberToString folder


5 - create a js file named YOUR-LANGUGE inside the functions/util folder

6 - edit and add your files to index.js inside the functions/util folder


7 - pull request

numbertotext's People

Contributors

fuzsh avatar sina-salami avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

sina-salami

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.