Wednesday 21 January 2015

Format currency according to culture in JavaScript


Convert number string to formatted currency string according to culture

function FormatStringToCurrency(val)
        {
            ///Convert string in float number
            var num = parseFloat(val);
            if (isNaN(num)) {
                return;
            }

            ///Find culture of browser
            var culture = navigator.language
            var formatted = num.toLocaleString(culture);
            var currency = num.toLocaleString(culture, { style: 'currency', currency: 'INR' });

        }

No comments:

Post a Comment