{"size": 1059, "ext": "js", "max_stars_repo_path": "archiviati/legacy/JSutils/moduli/_jsu_number_format.js", "max_stars_repo_name": "massimo-cassandro/front-end-utilities", "max_stars_repo_stars_event_min_datetime": "2020-03-03T16:36:30.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-23T22:00:04.000Z", "max_issues_repo_path": "archiviati/legacy/JSutils/moduli/_jsu_number_format.js", "max_issues_repo_name": "massimo-cassandro/front-end-utilities", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "archiviati/legacy/JSutils/moduli/_jsu_number_format.js", "max_forks_repo_name": "massimo-cassandro/front-end-utilities", "max_forks_repo_forks_event_min_datetime": "2020-08-14T14:34:43.000Z", "max_forks_repo_forks_event_max_datetime": "2020-08-14T14:34:43.000Z"}
{"max_stars_count": 3, "max_issues_count": null, "max_forks_count": 1, "avg_line_length": 24.6279069767, "max_line_length": 118, "alphanum_fraction": 0.5797922568}
/*globals JSutils:true*/

/*
  escapeHTML v. 1.1
  Massimo Cassandro 2015-2017
*/

JSutils = (function (utils) {
	"use strict";

	utils.number_format = function (number, decimals) {

	    if(decimals === undefined) decimals=0;
	    number = Number( number);

	    function toLocaleStringSupportsLocales() {
	        var nn = 0;
	        try {
	            nn.toLocaleString("i");
	        } catch (e) {
	            return e.name === "RangeError";
	        }
	        return false;
	    }

	    if(toLocaleStringSupportsLocales()) {
			number = Number(number.toFixed(decimals));
	        return number.toLocaleString("it-IT", { minimumFractionDigits: decimals });

	    } else {

	        // http://stackoverflow.com/questions/2254185/regular-expression-for-formatting-numbers-in-javascript
	        number = number.toFixed( decimals );
	        var number_parts = String(number).split('.');

	        return number_parts[0].replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1.") + ( decimals ? ',' + number_parts[1] : '');
	    }
	};

	return utils;

})(JSutils || {});
