Quote:
Originally Posted by berni
PHP Code:
stock FormatNumberInt(value, String:buffer[], size, seperator='.')
{
decl String:helper[size];
IntToString(value, helper, size);
strcopy(buffer, size, helper);
new length = strlen(helper);
new n_helper;
if (helper[0] == '-') {
n_helper += ((length-1) % 3) + 1;
if (n_helper == 1) {
n_helper = 4;
}
}
else {
n_helper += length % 3;
if (n_helper == 0) {
n_helper = 3;
}
}
new n_buffer = n_helper;
while (n_helper < length) {
buffer[n_buffer] = seperator;
strcopy(buffer[n_buffer + 1], size, helper[n_helper]);
n_buffer += 4;
n_helper += 3;
}
}
Mathematical version: (bit slower with big numbers)
PHP Code:
stock FormatNumber_(value, String:buffer[], size, seperator='.')
{
buffer[0] = '\0';
new divisor = 1000;
while (value >= 1000 || value <= -1000) {
new offcut = value % divisor;
value = RoundToFloor(float(value) / float(divisor));
Format(buffer, size, "%c%03.d%s", seperator, offcut, buffer);
}
Format(buffer, size, "%d%s", value, buffer);
return;
}
|
Now finally, thank you, sir, thank you very big. That works perfectly. Such a relief to finally have it. You should run for president or something - that's how smart and pretty you are. Even though I didn't get it why is "Mathematical version:
" is funnier than non mathematical one (need to learn more bout scripting, which I will go and do right away), laughed like a horse. Thank you, berni, have a nice day. as nice as possible