Skip to content

Convertor from dec10 numeral system to any greater system

License

Notifications You must be signed in to change notification settings

Connormiha/decimal-to-any

Repository files navigation

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

About

Convertor from dec10 numeral system to any greater system

Resources

License

Stars

Watchers

Forks

Packages

No packages published