How to convert a number to a string in JavaScript

Converting numbers to strings is essential for display formatting, template literals, API data preparation, and implementing features like form inputs or text concatenation in JavaScript applications. With over 25 years of experience in software development and as the creator of CoreUI, I’ve implemented number-to-string conversion extensively in components like displays, form fields, and data export features where presenting numeric values as readable text is crucial for user interfaces. From my extensive expertise, the most explicit and recommended approach is using the toString() method, which provides clear intent and optional formatting options. This method is reliable, widely supported, and offers additional control over number representation when needed.

Use the toString() method to convert a number to its string representation.

const number = 42
const stringValue = number.toString()
// Result: '42'

const floatNumber = 3.14159
const roundedString = floatNumber.toString()
// Result: '3.14159'

The toString() method converts the number to its string equivalent, preserving the numeric value as text. In these examples, 42.toString() becomes '42' and 3.14159.toString() becomes '3.14159'. The method handles integers, decimals, and scientific notation appropriately. You can also specify a radix (base) as a parameter: number.toString(16) converts to hexadecimal, number.toString(2) converts to binary. For literal numbers, use parentheses: (42).toString() to avoid syntax errors.

Best Practice Note:

This is the same approach we use in CoreUI components for formatting display values, preparing data for templates, and handling form input conversions across our component library. Alternative methods include String(number) for safety with null/undefined values, and template literals: `${number}` for embedding in strings. The toString() method is preferred for its explicit intent and optional formatting capabilities. Always consider locale-specific formatting for international applications.


Speed up your responsive apps and websites with fully-featured, ready-to-use open-source admin panel templates—free to use and built for efficiency.


About the Author