Convert Number to String Using toFixed() Method

The toFixed() method is used to round a number to two decimal places and return the result as a string.

Syntax:

let roundedNumber = number.toFixed(digits);

Example: Below is the practical implementation of the above method.

Javascript
let num: number = 10.555;
let roundedNum: string = num.toFixed(2);
console.log(roundedNum);
console.log(typeof roundedNum);

Output:

10.55
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

Similar Reads

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....

Convert Number to String Using Template Literals

Template literals are a feature in JavaScript (and TypeScript) that allows us to create multi-line strings and embed expressions within them....

Convert Number to String Using toFixed() Method

The toFixed() method is used to round a number to two decimal places and return the result as a string....

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....

Convert Number to String Using toLocaleString() Method

The toLocaleString() method converts a number into a string, using a locale-specific representation of the number. This method provides flexibility in formatting numbers based on different locales, such as specifying the language, country, and desired formatting options....

Contact Us