Skip to main content

Command Palette

Search for a command to run...

Format numbers using compact notation

Updated
1 min read
V

Engineer working in Cerebras. Latest work is Cerebras Inference. I love writing code in React, TypeScript, C++, Python. I spend most of my work hours tinkering with code.

const number = 2500000;

// Basic usage
const formatter = new Intl.NumberFormat('en-US', {
  notation: 'compact',
  compactDisplay: 'short' // 'short' or 'long'
});

console.log(formatter.format(number)); // "2.5M"
7 views