Giter Club home page Giter Club logo

d3-format-india's Introduction

d3-format-india

Indian Number System formatter.

Installing

If you use NPM, npm install d3-format-india. Otherwise, download the latest release.

API Reference

# formatIndia(value)

Formats the given number value using the Indian Number System. For example:

var formatIndia = require("d3-format-india").formatIndia;

console.log(formatIndia(10)); // Prints "10"
console.log(formatIndia(100)); // Prints "100"
console.log(formatIndia(1000)); // Prints "1,000"
console.log(formatIndia(10000)); // Prints "10,000"
console.log(formatIndia(100000)); // Prints "1,00,000"
console.log(formatIndia(1000000)); // Prints "10,00,000"
console.log(formatIndia(10000000)); // Prints "1,00,00,000"
console.log(formatIndia(10000000.4543)); // Prints "1,00,00,000.4543"
console.log(formatIndia(-1000000)); // Prints "-10,00,000"
console.log(formatIndia(-10000000.4543)); // Prints "-1,00,00,000.4543"

d3-format-india's People

Contributors

curran avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

d3-format-india's Issues

Fails on large numbers

At some point JavaScript starts Stringing numbers as '1e,+21'. I think we'd like to avoid this.

One solution may be to use d3-format internally, instead of the String constructor.

Failing tests are in the branch https://github.com/curran/d3-format-india/tree/large-numbers

# formatIndia() returns correctly formatted numbers using the Indian Number System.
ok 1 should be equal
ok 2 should be equal
ok 3 should be equal
ok 4 should be equal
ok 5 should be equal
ok 6 should be equal
ok 7 should be equal
ok 8 should be equal
ok 9 should be equal
ok 10 should be equal
ok 11 should be equal
ok 12 should be equal
ok 13 should be equal
not ok 14 should be equal
  ---
    operator: equal
    expected: '1,00,00,00,00,00,00,00,00,00,000'
    actual:   '1e,+21'
    at: Test.<anonymous> (/home/curran/repos/d3-format-india/test/format-india-test.js:21:8)
  ...
not ok 15 should be equal
  ---
    operator: equal
    expected: '1,00,00,00,00,00,00,00,00,00,00,000'
    actual:   '1e,+23'
    at: Test.<anonymous> (/home/curran/repos/d3-format-india/test/format-india-test.js:22:8)
  ...

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.