'How can I format price in javascript?

I have this PHP code below which can format product price. I want to do this same task with javascript. Is there any way to do this same task with javascript?

PHP

<?php echo number_format($saved_vehicles->Fields('basic_price'), 2, '.', ','); ?>


Solution 1:[1]

var number = 123456.789;

console.log(new Intl.NumberFormat('de-DE', { style: 'currency', currency: 'EUR' }).format(number));
// ? 123.456,79 €

console.log(new Intl.NumberFormat('ru-RU', { style: 'currency', currency: 'RUB' }).format(number));
// ? 123 456,79 ???.

console.log(new Intl.NumberFormat('ja-JP', { style: 'currency', currency: 'JPY' }).format(number))
// ? ?123,457

console.log(new Intl.NumberFormat('en-IN', { maximumSignificantDigits: 3 }).format(number));
// ? 1,23,000

your need to use Intl.NumberFormat. I think it's your choise

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Pete Pearl