/*
**     JavaScript Source Code
**     Created by Kalin Ganev
**     <KalinGanev [AT] Gmail (DOT) com>
**     Date Created:  2008-06-15
**     Last Modified: 2008-12-14
*/





/** It converts an input floating-point number to a string containing exactly 2 digits after the decimal point. */
function /*String*/ getPrecision2Float (fl_valueToConvert) {
	// 0.029943 = 0.03
	fl_valueToConvert = Math.round(fl_valueToConvert*100) / 100;
	str_result = fl_valueToConvert.toString();
	// Checking position of decimal point:
	int_posDecPoint = str_result.indexOf('.');
	if (-1 == int_posDecPoint) {
		// A decimal point does NOT exist (input value to convert is integer).
		str_result += '.00';
	} else {
		// A decimal point exists.
		if (int_posDecPoint == str_result.length-2) {
			str_result += '0';
		}
	}
	return str_result;
}


function /*String*/ getPrecision2FloatSi (fl_valueToConvert) {
	// Converting input floating-point number to a string containing exactly 2 digits after the decimal point:
	str_result = getPrecision2Float(fl_valueToConvert).toString();
	// Splitting result into an array containing 2 parts (integer part and fraction part)
	// by using the "point" character as a delimiter:
	arr_partsResult = str_result.split('.');
	// Adding extra point after every 3rd digit of integer part (part by index 0):
	str_part1WithPointsReversed = '';
	for (i=arr_partsResult[0].length-1, p=0; i>=0; i--, p++) {
		if (p>0 && 0==p%3) {
			// Current digit position is 3 or 6 or 9 or 12... (divisible by 3 without remainder).
			// Adding an extra point to reversed integer part:
			str_part1WithPointsReversed += '.';
		}
		// Copying current digit to reversed integer part:
		str_part1WithPointsReversed += arr_partsResult[0].charAt(i);
	}
	// Reversing the reversed integer part (normalizing it) and copying it back to parts array:
	arr_partsResult[0] = '';
	for (i=str_part1WithPointsReversed.length-1; i>=0; i--) {
		arr_partsResult[0] += str_part1WithPointsReversed.charAt(i);
	}

	// Concatenating both array parts by using a "comma" character instead of a "point" character
	// and returning result:
	return arr_partsResult[0] + ',' + arr_partsResult[1];
}


