How to split numbers and set a dot in it
#1

Hey,

how is it possible to split numbers and set points in it?

Example:

Before we split, we have $2582960, after we split, we have $2.582.960

Is there a filterscript or include for it?

I don't know what i should type in the search, sorry. Thanks for help.
Reply
#2

Well, the correct way is "$2,582,960" Meaning commas, not periods after three digits and yes, here you are:

pawn Код:
stock Comma(numbers)
{
    new temp[24],counter = -1;
    valstr(temp,numbers);
    for(new i = strlen(temp);i > 0; i--)
    {
        counter++;
        if(counter == 3)
        {
            strins(temp,",",i);
            counter = 0;
        }
    }
    return temp;
}
And anywhere you are defining the amount use:

pawn Код:
Comma(WhateverNumbers) //Whatever Number you want the commas within.
Reply
#3

using a point . for thousands separation is the common way in germany and some other areas where you use , as the decimal separator, so both variations are okay. To get the . as separator you just need to replace the , in strins with a . in his code of course.
Reply
#4

Quote:
Originally Posted by Mauzen
Посмотреть сообщение
using a point . for thousands separation is the common way in germany and some other areas where you use , as the decimal separator, so both variations are okay. To get the . as separator you just need to replace the , in strins with a . in his code of course.
Ah, I was not aware of that, haha. Thanks for the lesson, Mauzen.
Reply
#5

Quote:
Originally Posted by nmader
Посмотреть сообщение
Ah, I was not aware of that, haha. Thanks for the lesson, Mauzen.
Youre welcome
Though your version of course is the more handy one, else you would need to swap all the . decimal separators as samp uses them, with , to avoid mixing both versions.
Reply
#6

Thanks a lot guys.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)