Skip to content

Instantly share code, notes, and snippets.

@edgarMejia
Last active April 11, 2019 15:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save edgarMejia/87e1e90167295ce1df8c7094fc2d590a to your computer and use it in GitHub Desktop.
Save edgarMejia/87e1e90167295ce1df8c7094fc2d590a to your computer and use it in GitHub Desktop.
//https://developer.mozilla.org/es/docs/Web/JavaScript/Referencia/Objetos_globales/NumberFormat
var number = 123456.789;
// En el alemán la coma se utiliza como separador decimal y el punto para los millares
alert(new Intl.NumberFormat("de-DE").format(number));
// → 123.456,789
// En la mayoría de los países de lengua arábiga se utilizan también símbolos arábigos
alert(new Intl.NumberFormat("ar-EG").format(number));
// → ١٢٣٤٥٦٫٧٨٩
// En la India se utilizan separadores millares/lakh/crore
alert(new Intl.NumberFormat("en-IN").format(number));
// → 1,23,456.789
// use de nu para establecer un sistema numérico, el sistema decimal chino por ejemplo
alert(new Intl.NumberFormat("zh-Hans-CN-u-nu-hanidec").format(number));
// → 一二三,四五六.七八九
// cuando se requiera un lenguaje que pudiera no ser soportado, como es el caso del Balinés
// se recomienda incluir un lenguaje alternativo, en éste caso Indonesio
alert(new Intl.NumberFormat(["ban", "id"]).format(number));
// → 123.456,789
var number = 123456.789;
// se establece un formato de divisa
alert(new Intl.NumberFormat("de-DE", {style: "currency", currency: "EUR"}).format(number));
// → 123.456,79 €
// el yen japonés no tiene ninguna subdivisión
alert(new Intl.NumberFormat("ja-JP", {style: "currency", currency: "JPY"}).format(number))
// → ¥123,457
// limitamos a tres los dígitos significativos
alert(new Intl.NumberFormat("en-IN", {maximumSignificantDigits: 3}).format(number));
// → 1,23,000
//https://developer.mozilla.org/es/docs/Web/JavaScript/Referencia/Objetos_globales/NumberFormat
var number = 3500;
alert(new Intl.NumberFormat().format(number));
// → "3,500" si el código de idioma es US English
var number = 123456.789;
console.log(new Intl.NumberFormat('de-DE', { style: 'currency', currency: 'EUR' }).format(number));
// expected output: "123.456,79 €"
// the Japanese yen doesn't use a minor unit
console.log(new Intl.NumberFormat('ja-JP', { style: 'currency', currency: 'JPY' }).format(number));
// expected output: "¥123,457"
// limit to three significant digits
console.log(new Intl.NumberFormat('en-IN', { maximumSignificantDigits: 3 }).format(number));
// expected output: "1,23,000"
// TODO LO ANTERIOR APLICADO A:
/*
* @param value double or integer
* @param useCurrency boolean, for use or not currency symbol.
* @returns {string}
*/
function normalizeMoney(value, useCurrency) {
var currency = (useCurrency!==null && useCurrency!==undefined && useCurrency) ?
CONSTANTS.parameters.generalConfig.currency : '' ;
if(value===null || value===undefined || isNaN(value)) return currency + '00.00';
return currency + new Intl.NumberFormat("es-SV", {minimumFractionDigits: 2, maximumFractionDigits: 2}).format(value);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment