Little question :)
#1

Hey all,
I have a question - How can I simplify this code? Is there any way?!

there is the code:
Код:
stock IntegerWithDelimiter(integer, delimiter[] = ",") { //32 bit digit, max - 2147483647 and on every 3 diggits adds delimiter
	new string[16];
	if(integer >= 0) {
		format(string, sizeof(string), "%d", integer);
		if(1000 <= integer < 10000) strins(string, delimiter, 2, sizeof(string));
		else if(10000 <= integer < 100000) strins(string, delimiter, 3, sizeof(string));
		else if(100000 <= integer < 1000000) strins(string, delimiter, 4, sizeof(string));
		else if(1000000 <= integer < 10000000) { strins(string, delimiter, 2, sizeof(string)); strins(string, delimiter, 6, sizeof(string)); }
		else if(10000000 <= integer < 100000000) { strins(string, delimiter, 3, sizeof(string)); strins(string, delimiter, 7, sizeof(string)); }
		else if(100000000 <= integer < 1000000000) { strins(string, delimiter, 4, sizeof(string)); strins(string, delimiter, 8, sizeof(string)); }
		else if(integer >= 1000000000) { strins(string, delimiter, 2, sizeof(string)); strins(string, delimiter, 6, sizeof(string)); strins(string, delimiter, 10, sizeof(string)); }
	} else {
		format(string, sizeof(string), "-%d", integer - (integer * 2));
		if(-1000 >= integer > -10000) strins(string, delimiter, 3, sizeof(string));
		else if(-10000 >= integer > -100000) strins(string, delimiter, 4, sizeof(string));
		else if(-100000 >= integer > -1000000) strins(string, delimiter, 5, sizeof(string));
		else if(-1000000 >= integer > -10000000) { strins(string, delimiter, 3, sizeof(string)); strins(string, delimiter, 7, sizeof(string)); }
		else if(-10000000 >= integer > -100000000) { strins(string, delimiter, 4, sizeof(string)); strins(string, delimiter, 8, sizeof(string)); }
		else if(-100000000 >= integer > -1000000000) { strins(string, delimiter, 5, sizeof(string)); strins(string, delimiter, 9, sizeof(string)); }
		else if(integer <= -1000000000) { strins(string, delimiter, 3, sizeof(string)); strins(string, delimiter, 7, sizeof(string)); strins(string, delimiter, 11, sizeof(string));}
	}
	return string;
}
please help...
Reply


Messages In This Thread
Little question :) - by bgedition - 31.05.2015, 15:34
Re: Little question :) - by Konstantinos - 31.05.2015, 15:58
Re: Little question :) - by Vince - 31.05.2015, 16:54
Re: Little question :) - by Konstantinos - 31.05.2015, 17:29
Re: Little question :) - by bgedition - 31.05.2015, 17:44
Re: Little question :) - by bgedition - 01.06.2015, 11:12
Re: Little question :) - by Konstantinos - 01.06.2015, 11:25
AW: Little question :) - by Kaliber - 01.06.2015, 11:26
Re: Little question :) - by bgedition - 01.06.2015, 11:49

Forum Jump:


Users browsing this thread: 1 Guest(s)