var NB = {};
NB.Math = function()
{
	return  {
		GetFloat : function(str, precision)
		{
			// if already numeric value
			if(typeof(str) == "number")
				return this.FormatFloat(str, precision);
			if(str == null || str == "")	return 0;
			
			str.indexOf(",");
			str = str.replace(",",".");
			str = str.replace(" ", "");
			re = new RegExp("([0-9.]+)");
			result = str.match(re);
			if(result != null)
				str = result[0];
			str = parseFloat(str);	
			if(isNaN(str)) str = 0;
			
			return this.FormatFloat(str, precision);
		},
		FormatFloat : function(num, precision)
		{
			num = parseFloat(num);
			if(!isNaN(num))
			{
				num *= Math.pow(10, precision);
				num  = Math.round(num);
				num /= Math.pow(10, precision);
			}
			else
				return "NaN";
			return num;
		},
		FormatNumber : function(num, decplaces, decPointChar, thousandsSepChar)
		{
			var num = (String)(num);
			num = num.replace(",", ".");
			var re = new RegExp("^([0-9]|[0-9]{2}|[0-9]{3}])?(([0-9]{3})*)(\\.[0-9]*)?$", "i");
			var matches = re.exec(num);

			var dec = 0;
			if(typeof(matches[4]) == "string")
			{
				dec = (matches[4].replace(".", ""));
			}
			
			var thousandGroups = [];
			if(typeof(matches[2]) == "string")
			{
				for(var i = 0; i < matches[2].length; i+=3)
				{
					thousandGroups[thousandGroups.length] = matches[2].substr(i, 3);
				}
			}
			
			var numberBegin = "";
			if(typeof(matches[1]) == "string")
			{
				numberBegin = matches[1];
			}
			
			var numberMiddle = thousandGroups.join(thousandsSepChar);
			
			if(numberBegin.length > 0 && numberMiddle.length > 0)
			{
				numberBegin += thousandsSepChar;
			}
			
			
			var numberEnd = "";
			if(decplaces > 0)
			{
				numberEnd += dec;
				for(var i = numberEnd.length; i < decplaces; i++)
				{
					numberEnd += "0";
				}
			}
			
			var output = numberBegin + numberMiddle + decPointChar + numberEnd;
			return output;
		}
	};
}();

