Decimal Point float
#1

Alright so the problem is quite simple, im trying to use %.2f combined with decimal point, altho theres someting wrong with this

My cash at the moment is
383100.00 (yes I am using cash as a float)

and the print is
38311,00,00 (not sure if the last diggits are .00 or ,00 since the textdraw font is glitched atm, trying to get it to work with , and .)

Well, I am trying to get it to look like this

383,100.00$

the .00 would of course get from .2f (for example it can be .50$ etc) all in all, cents.

the code is
PHP код:
stock DecimalPoint(Float:money)
{
    new 
str[16];
    if(
money >= 0)
    {
            
format(strsizeof(str), "%.2f$"money);
            if(
1000 <= money 10000strins(str","2sizeof(str));
            else if(
10000 <= money 100000strins(str","3sizeof(str));
            else if(
100000 <= money 1000000strins(str","4sizeof(str));
            else if(
1000000 <= money 10000000) { strins(str","2sizeof(str)); strins(str","6sizeof(str)); }
            else if(
10000000 <= money 100000000) { strins(str","3sizeof(str)); strins(str","7sizeof(str)); }
            else if(
100000000 <= money 1000000000) { strins(str","4sizeof(str)); strins(str","8sizeof(str)); }
            else if(
money >= 1000000000) { strins(str","2sizeof(str)); strins(str","6sizeof(str)); strins(str","10sizeof(str)); }
    }
    else
    {
            
format(strsizeof(str), "-%.2f$"money-(money*2));
            if(-
1000 >= money > -10000strins(str","3sizeof(str));
            else if(-
10000 >= money > -100000strins(str","4sizeof(str));
            else if(-
100000 >= money > -1000000strins(str","5sizeof(str));
            else if(-
1000000 >= money > -10000000) { strins(str","3sizeof(str)); strins(str","7sizeof(str)); }
            else if(-
10000000 >= money > -100000000) { strins(str","4sizeof(str)); strins(str","8sizeof(str)); }
            else if(-
100000000 >= money > -1000000000) { strins(str","5sizeof(str)); strins(str","9sizeof(str)); }
            else if(
money <= -1000000000) { strins(str","3sizeof(str)); strins(str","7sizeof(str)); strins(str","11sizeof(str));}
    }
    return 
str;

EDIT v1: I justed tested it as %f instead of %.2f and I got the results of
3831,00.0000000$
Almost correct. Just gotta get it to be
381,100.00$
Reply
#2

Here, I present to you: "formatnumber.inc".

Edit: np
Reply
#3

Thanks sexy! +rep
Reply
#4

What is commonly advised here in the land of C#, don't use Float for a currency. If you want your currency to be rouded to cents, store it as an integer multiple of a cent.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)