count-digits

1.0.0 • Public • Published

count-digits

master branch build status

Counts the digits of an integer in any base.

Usage

countDigits(value[, base=10])

Example

var countDigits = require('count-digits');
 
countDigits(100);  // => 3
countDigits(1000); // => 4
countDigits(1e4);  // => 5
countDigits(0xff, 16); // => 2
countDigits(0xff, 2);  // => 8

Installing

$ npm install --save count-digits

Notes

Zero

Zero is a special case when counting digits. Be aware that countDigits(0) will return 0 where you might be expecting 1.

Floats

Since only whole values are counted, countDigits(Math.PI) will return 1.

License

MIT.

Package Sidebar

Install

npm i count-digits

Weekly Downloads

1

Version

1.0.0

License

MIT

Last publish

Collaborators

  • j-