Convert Number to String Using toString() Method
In this approach, we are using toString() method. That is used to convert a value to a string. we will pass the numeric value and it will convert that value into a string.
Syntax:
Object.toString()
Example: In the below code we are passing the number value to the toString() method which converts the float to a string.
let numberValue: number = 7.577474;
let stringValue: string = numberValue.toString();
console.log(stringValue);
console.log(typeof stringValue);
Output:
7.577474
string
How to Convert Number to String in TypeScript ?
Converting floats to strings is a common operation in programming that enables us to work with numeric data in a more flexible and controlled manner.
Below are the approaches:
Table of Content
- Using toString() Method
- Using Template Literals
- Using toFixed() Method
- Using String Constructor
- Using toLocaleString() Method