var num1 = 10;
console.log(num1.toFixed(2))
var num1 = 15.456789;
console.log(num1.toFixed())
3 Likes
problem 1= 10
problem 2=15
2 Likes
answer is; 10.00, 15
2 Likes
first 10.00 and then 15
2 Likes
results are 10.00 and 15
2 Likes
ans 1 = 10.00
ans 2 = 15.45
2 Likes
answer is; 10.00, 15
2 Likes
The answer is
- 10.00
2.15
1 Like
Actually toFixed() method comes in ES3. It converts number into string with specified decimal value…we have to specify the decimal value limit in parenthesis if we do not specified it takes default value as 0.
in your question num1 =10; will be converted into string (output : “10”)
For num1 = 15.456789; will be converted into string ( output : “15”) here we didn’t specified decimal value so it taken default value as 0
2 Likes
the answer 10.00, 15
2 Likes
[quote=“athira_ta_fsr, post:1, topic:689, full:true”]
var num1 = 10;
console.log(num1.toFixed(2))
var num1 = 15.456789;
console.log(num1.toFixed())
Ans1: 10.00
Ans2: 15
1 Like