Convert Number to String Using String Constructor
The String constructor can be used to create a new string object. It can also be used to convert a value to a string. in this approach we will see how we can convert float value to string using String Constructor.
Syntax:
let str: string = String(floatValue);
Example: In this example, String(num) converts the number 123.78 into a string “123.78” using the String constructor.
let num: number = 123.78;
let str: string = String(num);
console.log(str);
console.log(typeof str);
Output:
123.78
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
Contact Us