Simple Numbers Format Help

Asked

Viewed 34 times

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 unsuccessfully!

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
  • 1

    total.toFixed(2);

1 answer

0


With the Precision to display how you want only do not know if it satisfies the use:

toPrecision

var total = 10.90;


totalrealF = parseFloat(total).toPrecision(4)


console.log(totalrealF)

reference : W3school

  • Thank you! simple!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.