Home Web Front-end JS Tutorial Several ways to add thousand characters to formatted numbers in node.js_node.js

Several ways to add thousand characters to formatted numbers in node.js_node.js

May 16, 2016 pm 03:51 PM
node.js number format

Separate every three characters with commas

Regular method:

Copy code The code is as follows:

"15000000".split("").reverse().join("").replace(/(d{3})/g, "$1,").split("").reverse().join( "");

"115000000".split("").reverse().join("").replace(/(d{3})(?=[^$])/g, "$1,").split ("").reverse().join("");

var str = '123123211312.333123'.replace(/(?=(?!^)(?:d{3}) (?:.|$))(d{3}(.d $)?)/ g,',$1');
console.log(str)

'1500000000000'.replace(/B(?=(d{3}) $)/g,',')

Loop search method

Copy code The code is as follows:

function formatNumber(value) {
value = value.toString();
If (value.length <= 3) {
         return value;
} else {
            return formatNumber(value.substr(0, value.length - 3)) ',' value.substr(value.length - 3);
}
}

toLocaleString function:

Copy code The code is as follows:

15000000..toLocaleString();
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to format c drive with dos command How to format c drive with dos command Feb 19, 2024 pm 04:23 PM

DOS command is a command line tool used in Windows operating system, which can be used to perform various system management tasks and operations. One of the common tasks is to format the hard drive, including the C drive. Formatting the C drive is a relatively dangerous operation because it will erase all data on the C drive and reinitialize the file system. Before performing this operation, make sure you have backed up important files and have a clear understanding of the impact that formatting will have on your computer. The following is formatted in the DOS command line

Revealed secrets of cell phone format recovery methods (mobile phone malfunction? Don't worry) Revealed secrets of cell phone format recovery methods (mobile phone malfunction? Don't worry) May 04, 2024 pm 06:01 PM

Nowadays, we will inevitably encounter some problems such as being unable to turn on the phone or lagging, such as system crash, but during use, mobile phones have become an indispensable part of our lives. We are often at a loss, and sometimes, there are no solutions to these problems. To help you solve cell phone problems, this article will introduce you to some methods of cell phone format recovery and restore your phone to normal operation. Back up data - protect important information, such as photos and contacts, from being lost during the formatting process. Before formatting your phone, the first thing to consider is to back up important data and files on your phone. To ensure data security, or choose to transfer files to a cloud storage service, you can back it up by connecting to a computer. Use the system's built-in recovery function - simple

Will formatting a laptop make it faster? Will formatting a laptop make it faster? Feb 12, 2024 pm 11:54 PM

Will formatting a laptop make it faster? If you want to format your Windows laptop but want to know if it will make it faster, this article will help you know the right answer to this question. Will formatting a laptop make it faster? There are many reasons why users format their Windows laptops. But the most common reason is slow performance or speed of your laptop. Formatting a laptop will completely delete all data stored on the C drive or the hard drive partition where Windows operating system is installed. Therefore, every user will think twice before taking this step, especially when it comes to the performance of the laptop. This article will help you understand whether formatting your laptop will speed it up. Formatting your laptop helps

Computer formatting tutorial Computer formatting tutorial Jan 08, 2024 am 08:21 AM

Many times when using a computer, you will encounter too much garbage, but many users still don’t know how to format the computer. It doesn’t matter. Here is a tutorial on computer formatting for you to take a look at. How to format a computer: 1. Right-click "This PC" on the desktop and click "Manage". 2. Click "Storage" in "Computer Management" to open "Disk Management". 3. Select the hard drive you want to clean, right-click and select "Format". 4. Check "Perform Quick Format" and click "OK" to start formatting.

What are the methods of html formatting? What are the methods of html formatting? Mar 08, 2024 am 09:53 AM

HTML formatting method: 1. Use online HTML formatting tools; 2. Use the HTML formatting shortcut keys that come with the code editor, such as Shift + Alt + F in Visual Studio Code; 3. Use plug-ins, such as Sublime Text HTML/CSS/JS Prettify plug-in; 4. Use command line tools, such as HTML Tidy; 5. Manual formatting according to coding standards and habits.

What is the formatting shortcut key in Eclipse? Comprehensive analysis! What is the formatting shortcut key in Eclipse? Comprehensive analysis! Jan 03, 2024 pm 02:41 PM

Eclipse is an integrated development environment (IDE) widely used in Java development. It provides many features and tools that enable developers to write and debug code more efficiently. One of the very important and commonly used functions is code formatting, which can help developers unify their code style and improve the readability and maintainability of the code. In Eclipse, we can use shortcut keys to quickly format code. This article will introduce the commonly used code formatting shortcut keys in Eclipse and analyze them in detail.

Use shortcut keys in Eclipse to easily complete code formatting Use shortcut keys in Eclipse to easily complete code formatting Jan 03, 2024 am 09:59 AM

Eclipse is a very popular Java integrated development environment (IntegratedDevelopmentEnvironment, IDE). It provides many functions and shortcut keys to facilitate developers to improve efficiency. One of the commonly used functions is code formatting. This article will introduce the formatting shortcut key in Eclipse and how to use it. In Eclipse, code formatting is a very important operation. By formatting your code, you can make it

How to format and reinstall the win10 system_Format and reinstall the win10 system tutorial How to format and reinstall the win10 system_Format and reinstall the win10 system tutorial Mar 21, 2024 pm 04:56 PM

Nowadays, the security of Windows 10 system computers is threatened by many viruses and programs. Let’s take a typical example. When he is surfing the Internet, he will unintentionally open a link or website, and then some very annoying advertisements will pop up on our computer inexplicably. Or if the computer is stuck in the interface and cannot move, it is likely that some software has been maliciously bundled and installed. Another situation is that there is a virus in the computer. If this kind of problem occurs, we can reinstall the system on the win10 computer, which can effectively remove the virus programs in the system disk. Now the editor will show you how to format and reinstall the win10 system. Let's read on. . 1. How to format and reinstall the win10 system? First, we click &quot;Start&quot; -

See all articles