Format and Manipulate Numbers With Numeral.js
Join the DZone community and get the full member experience.Join For Free
Once you have added the dependency, create an instance of numeral. The constructor takes numbers or strings.
let testNumeral = numeral(10000); testNumeral.format('0,0'); >> 10,000
Converting to Currency
testNumeral = numeral(10000); testNumeral.format('$0,0.00'); >> $10,000.00
Converting to Bytes
testNumeral = numeral(1024); testNumeral.format(' 0b'); //1KB
Numeral.js is a great library and easy to use. If you want to learn more about it, check out the website for documentation and examples.
Published at DZone with permission of Swathi Prasad, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.