When we use tofixed() function it converts a number to a string na. then why my ans is marked wrong when i selected "123" as answer for var num1 = 123.4567 console.log(num1.toFixed())

when we use tofixed() function it converts a number to a string na? then why my answer is marked wrong when i selected “123” as a answer for var num1 = 123.4567 console.log(num1.toFixed())

1 Like

@ballapriya2608

Hello,

We have recieved your query.
This was a really nice question which you have asked.

Give us a couple of minutes & we will reach out with the solution for your query

Zeba Kainat| TA- Edyoda

Hi ballapriya2608,
You are correct, The toFixed() method converts a number to a string . The toFixed() method rounds the string to a specified number of decimals.

var num1 = 123.4567 console.log(num1.toFixed()) //answer: "123"

Hi ballapriya2608,

toFixed() converts a number to a string, rounded to a specified number of decimals:

So for eg:-

Let answer = 5.6578

Console.log(answer.toFixed(2));

5.65 //

1 Like

yes i know that i just wanted to know thw type of that ans will be string na

2 Likes

@ballapriya2608 yes , it will be a string

3 Likes