Giter Club home page Giter Club logo

decimal-to-any's Introduction

Build Status

decimal-to-any NPM version

Convert decimal number to any other numeral system. Support user's alphabet.

Usage

Simple usage without alternative alphabet

Convert 256 decimal number to hex

var decToAny = require('decimal-to-any');
decToAny(256, 16); // '100'

Convert 100 decimal number to base 6 numeral system

decToAny(100, 6); // '244'

Convert 200.1 decimal number to base 30 numeral system

decToAny(200.1, 30); // '6k.3'

Convert 20 decimal number to binary

decToAny(20, 2); // '10100'

API

decimal-to-any(number, numeralSystem[, options])

number

Type: Number, String

The decimal number for convert. 100, 100.1, "100.1"

numeralSystem

Type: Number

The numeral system for output.

options

Type: Object

options.alphabet

Type: Array, String
Default: "0123456789abcdefghijklmnopqrstuvwxyz"

Alternative alphabet for output.

var options = {
    alphabet: '!@#$%^&*()_+={}<>±'
};

decToAny(100, 16, options)// '&%'
decToAny(200.002, 16, options)// '=(.!!($@#&})*({%<}'

Example for understanding. DEC to DEC with user's alphabet. It's just example. It's better to use here String.replace :)

var options = {
    alphabet: '@123456789'// 'at' symbol instead of 0
};

decToAny(100, 10, options)// '1@@'

Important: if you want to use numeral system with base higher than the default alphabet length (example: base 50), you should define new alphabet via options.alphabet.

options.precision

Type: Number
Default: 20

Quantity of numbers after point

decimal-to-any's People

Contributors

connormiha avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

Forkers

vitaly-z

decimal-to-any's Issues

v1.0.2 has breaking changes

I just updated to v1.0.2 and realized that in index.js@convertorInteger the last parameter changed to { alphabet }. Object destruction is not supported in Node v<6.

As in your package.json engines is set to v4.2.0 I guess this might be a breaking change instead of an patch release.

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.