JavaScript in Depth
JS: Format Number
By Xah Lee. Date:
2015-03-06
. Last updated:
2026-07-17
.
JavaScript does not have a “format” or “printf” function. The following code are solutions.
Format with separator, money, metrix prefix, percentage, etc.
JS: Number .prototype .toLocaleString
To string, n decimal places
JS: Number.prototype.toFixed
To string, n significant digits
JS: Number.prototype.toPrecision
To string, scientific notation
JS: Number.prototype.toExponential
String Template
JS: Template String
Number to String, hexadecimal, binary
JS: Number.prototype.toString (Number to String)
JavaScript. format number
JS: Format Number
JS: Number .prototype .toLocaleString
JS: Number.prototype.toFixed
JS: Number.prototype.toPrecision
JS: Number.prototype.toExponential
JS: Intl.NumberFormat
JS: Math ceiling, floor, round, truncate
JavaScript. Number
JS: Number
JS: Number Input. Binary, Hexadecimal, Octal, Etc
JS: BigInt tutorial
JS: Assignment Operators
JS: Arithmetic Operators
JS: Number Comparison Operators
JS: Convert String and Number
JS: Convert Decimal, Hexadecimal
JS: Convert Decimal, Binary
JS: Format Number
JS: Random Integer Range Function 📜
JS: Number (class)
JS: Number Constructor
JS: Number.prototype
JS: Math (namespace)
Webdev Search 🔍
JavaScript in Depth
Basics
Filename Extension
Run JavaScript
Comment
Print
Quote String
Number
Math Operators
Assignment
Boolean
Test Equality
Conditional
Loop
Array basics
Object basics
Advanced
Value Types
Variable
String
Regex
Property
Object
Array
Function
Class
Iterable
Misc
Module
Try Catch Throw
ECMAScript News
Misc index
Misc. Index
Obj Ref
JS Object Reference