All pastes #116602 Raw Edit

Stuff

public text v1 · immutable
·published 2006-08-05 11:11 UTC
rendered paste body
		function format_number(num)
		{
			var str = num.toString();
			var char, hundreths, thousanths;
			var formatted;
			
			if ( (char = str.indexOf(".")) > -1)
			{
				hundreths = parseInt(str.substring(char + 2, char + 3));
				thousanths = parseInt(str.substring(char + 3, char + 4));

				if (thousanths > 5) hundreths += 1;
				else hundreths -= 1;
				
				formatted = str.substring(0, char + 2);

				if (hundreths > 0)
					formatted += hundreths.toString();
				
				return( formatted );
			} else
				return( num );
		}