31.05.2015, 15:34
Hey all,
I have a question - How can I simplify this code? Is there any way?!
there is the code:
please help...
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; }