adamwdraper / Numeral-js

A javascript library for formatting and manipulating numbers.
http://numeraljs.com
MIT License
9.66k stars 930 forks source link

Padding/Minimal length for numbers (formatNumber) #123

Open resident-uhlig opened 10 years ago

resident-uhlig commented 10 years ago

I could not find a way to pad numerical values with numeral.js.

Below all comparisons should be true.

var format;
format = '#3#'; // min length = 3
numeral(1).format() === '001';
numeral(10).format() === '010';
numeral(100).format() === '100';
numeral(1000).format() === '1000';

format = '#4#0,0.0'; // min length = 4
numeral(1).format() === '0,001.0';
numeral(10).format() === '0,010.0';
numeral(100).format() === '0,100.0';
numeral(1000).format() === '1,000.0';

I have added a few lines in formatNumber(). Maybe you want to include this into your original version. See: https://gist.github.com/resident-uhlig/7906919

There are UIs that require this kind of padding.

See also #43

mcross1882 commented 9 years ago

Are there any updates on this issue? I am currently using this library for production purposes and this feature would greatly help. I would be happy to supply a PR if the project maintainer is good with that?

BenjaminVanRyseghem commented 9 years ago

Please have a look at https://github.com/foretagsplatsen/numbro/issues/76 :smile:

fhackenberger commented 9 years ago

@adamwdraper Would you mind pulling this and tagging a new release? I'd love to avoid patching it locally :-D

BenjaminVanRyseghem commented 9 years ago

@fhackenberger this project seems dead as we are pinging the author for months now without any answer.

But numbro is an active fork of it

fhackenberger commented 9 years ago

@BenjaminVanRyseghem cheers!

mcross1882 commented 9 years ago

Thanks for the work on this guys!