Format number with javascript

Asked

Viewed 472 times

-1

I have the following value: 7500 How do I get that value as a final result: 75.00, would like to use pure javascript only.

Other examples:

76000 > 760.00
1600 > 16.00

I tried toFixed but it didn’t work

var number = 76900
var value = parseFloat(Math.round(number * 100) / 100).toFixed(2)
console.log(value)//Esperava 769.00 como resultado

  • 1

    To confirm, you divided by 100 before using the toFixed? https://repl.it/@acwoss/AjarAshamedInstitute

  • I put an example of how I did @Andersoncarloswoss

  • 1

    Why multiplied by 100 too?

  • 1

    Takes the * 100, nor the Math.round makes sense there :/ at least not at first sight. The .toFixed(2) already solves almost "everything".

  • solved, I took the * 100

1 answer

0

Solved, I used parseFloat(Math.round(number / 100)).toFixed(2)

Browser other questions tagged

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