Number format help in simple mode [duplicate]

0

I think my question is silly, but I never got to take that test. has some way to recover the value so 10.90 with zero without using function or replace, I have tried here more without success!

var total = 10.90;

totalreal = parseInt(total)
totalrealF = parseFloat(total)
totalrealN = Number(total)

document.write(

'R$ ' + totalreal +  '<br>' +
'R$ ' + totalrealF + '<br>' +
'R$ ' + totalrealN + '<br>' +
'R$ ' + total +          '<br>'

);

exit

R$ 10
R$ 10.9
R$ 10.9
R$ 10.9

desired

R$ 10.90
    
asked by anonymous 18.07.2018 / 17:32

1 answer

0

With the precision of the to display as you wish only do not know if it satisfies the use:

  

toPrecision

var total = 10.90;


totalrealF = parseFloat(total).toPrecision(4)


console.log(totalrealF)
  

reference: W3school

    
18.07.2018 / 17:46