Best Way Format And Manipulate Numbers In JavaScript

Full Stack Developer | Freelancer | JavaScript | React | Nodejs.
Loves sharing knowledge through technical articles.
Dev.to: https://dev.to/myogeshchavan97
https://linktr.ee/myogeshchavan97
Search for a command to run...

Full Stack Developer | Freelancer | JavaScript | React | Nodejs.
Loves sharing knowledge through technical articles.
Dev.to: https://dev.to/myogeshchavan97
https://linktr.ee/myogeshchavan97
No comments yet. Be the first to comment.
In this tutorial, you will build a Task Management App using Next.js 16 and Prisma 7 from scratch. By creating this app, you will learn: How to set up Prisma 7 with the new Rust-free architecture How to configure a database with Prisma's driver ada...

If you're a React/Next.js developer who diligently updated your packages last week after the critical React2Shell vulnerability (CVE-2025-55182), I have some frustrating news: you need to update again. Security researchers, while probing the patches ...

Is your React app dragging its feet, but you can’t pinpoint the cause? You might think you’re following the best practices, but some common development patterns are actually degrading your app’s performance behind the scenes. In this article, we’ll u...

How to Use Separate SSH Keys for Company and Personal GitHub Accounts Managing multiple GitHub accounts is a common challenge for developers who juggle both personal and professional projects. It becomes even more complex when you want to use differe...

Have you ever built a React app only to realize that users from different countries can't use it effectively because it only supports English? In this tutorial, you'll learn how to build truly global React application using internationalization (i18n...

Today we will see a very popular and easy-to-use library that allows us to convert and manipulate numbers.
Many times we need to display numbers like 1400 to 1.4k, 1000000 to 1M which may be numbers of views, likes or comments.
Sometimes we need to add commas in long numbers to easily understand it.
It's very difficult to handle all the scenarios ourselves.
So to make our task easier there is a library known as Numeral.
Let's understand how to use it.
There are two ways of using it.
We will use the second way of npm.
To install the package, execute the following command:
npm install numeral
OR
yarn add numeral
import numeral from "numeral"; // ES6
OR
const numeral = require('numeral'); // Nodejs
const commaSeparated = numeral(50000).format("0,0");
console.log(commaSeparated); // 50,000
const kFormatted = numeral(23000).format("0a");
const mFormatted = numeral(1230974).format("0.000a");
console.log(kFormatted); // 23k
console.log(mFormatted); // 1.321m
const ordinal = numeral(23).format("0o");
console.log(ordinal); // 23rd
const bytes = numeral(2348895676).format("0.00b");
console.log(bytes); // 2.35GB
const exponential = numeral(676565765722).format("0,0e+0");
console.log(exponential); // 7e+11
To explore other formats and examples visit http://numeraljs.com/.
Check out my recently published Mastering Redux course.
In this course, you will build 3 apps along with a food ordering app and you'll learn:
and then finally we'll build a complete food ordering app from scratch with stripe integration for accepting payments and deploy it to the production.
Want to stay up to date with regular content regarding JavaScript, React, Node.js? Follow me on LinkedIn.