[Include] formatnumber.inc - Human-readable numbers ( 10000000 -> 10 000 000 )
#1

hey,
This is not another number formatter function. With this, you can format any variable type without having to change anything. Before you lose interest, allow me to re-attract your interest by providing a bullet-list!
  • Set the thousand separator (or disable it)
  • Set the number of decimals
  • Set the decimal point
  • Format hex numbers without getting invalid values on high numbers
More information is inside the include.

Examples:
pawn Код:
new
    iNumber = 4864334,
    Float:fFloat = 55548623.112,
    bool:bFalse = false,
    bool:bTrue = true
;

printf( FormatNumber( iNumber ) );
printf( FormatNumber( fFloat, 3, ',', '.' ) );
printf( FormatNumber( bFalse ) );
printf( FormatNumber( bTrue ) );
printf( FormatNumber( fFloat, 0 ) );
printf( FormatNumber( iNumber, 2, 0 ) );
printf( FormatNumber( hex:fFloat ) );
printf( FormatNumber( bit:0b00100110 ) );
printf( FormatNumber( bit_byte:0b10101010101010101010101010101011 ) );
Will print:
Код:
4 864 334
55,548,624.000
false
true
55 548 624
4864334.00
0x4C53E6B4
0b00100110
0b10101010101010101010101010101011
Download!
Reply
#2

interesting good idea
Reply
#3

Not bad, I'm liking this.
Reply
#4

Quote:
Originally Posted by ******
Посмотреть сообщение
I like your use of tagof!

Also:

pawn Код:
format( s_szReturn, sizeof( s_szReturn ), "%.*f", iDecimals, xVariable );
Thanks, I felt kinda awkward about that part. Updated.
I'm quite amazed I got the tagof way working flawless; I'm just starting to realize how useful tagof actually can be.

Edit:

Update
You can now print out either the first 8 bits (using the bit_byte: tag), or all 32 bits (using the bit: tag).
Reply
#5

awesome..!
Reply
#6

nice i like it
Reply
#7

Awesome.
Reply
#8

Why not change it from "FormatNumber" to "fnum" or something? ^.^
Reply
#9

Quote:
Originally Posted by SWEMike
Посмотреть сообщение
Why not change it from "FormatNumber" to "fnum" or something? ^.^
Do that yourself And since when a name of a function counts so much?


Код:
This forum requires that you wait 120 seconds between posts. Please try again in 1 seconds.
Can't believe that happened O_o
Reply
#10

Quote:
Originally Posted by SWEMike
Посмотреть сообщение
Why not change it from "FormatNumber" to "fnum" or something? ^.^
Cause it's ugly - like your face.
Reply
#11

Dont talk about his face!!!! He cant help it that his face is ugly!

This forum requires that you wait 120 seconds between posts. Please try again in 1 seconds.
T_T Did....did that just..... realy happend.... to me?
Reply
#12

1 seconds!!!!!!!!
Reply
#13

Nice work Slicez
Reply
#14

Why did you include the DB and DBResult tags in the parameter?

EDIT and why not for kicks add in economical punctuation ($1,000,000.00) and chronical format (01:32:500, MM:SS:mmm)
Reply
#15

Quote:
Originally Posted by Slice
Посмотреть сообщение
Cause it's ugly - like your face.
Well, then I suppose fprint is ugly aswell. I was just suggesting a small thing but apparently it's not allowed here.
And you haven't seen my face so you can't really know. :P

I like this include no matter what the name of the function is.

EDIT: "This forum requires that you wait 60 seconds between reporting posts. Please try again in 1 seconds." LOL! : )
Reply
#16

interesting job.
Reply
#17

how i make to bank money to make to zecimal?on /stats
Reply
#18

Vert cool
Reply
#19

Well, it's a great work, but..

I have a problem:
Код:
..\pawno\include\FORMATNUMBER.inc(112) : error 020: invalid symbol name ""
And:
Код:
else if ( iTag == tagof( hex: ) || iTag == tagof( Hex: ) )
Can you help me ?
Reply
#20

What do you compile it with?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)