Number Formatting
Simple stock for formating numbers.
Returns number as string. If only_num bool is set to false it will return formated number with commas ( 10,000 ) if true then with abbreviation ( 10k ). If number is not round ( 2.3m, 10k, 159k ) it will be formated with commas ( 2,300,001 ). At the moment it will only format till 999,999,999 after that it will output without commas or abbreviation in string. Examples: ------------------------------------------------- format_number(10000, true) Result 10,000 ------------------------------------------------- format_number(10000, false) or format_number(10000) Result 10k ------------------------------------------------- format_number(2300000 , true) Result 2,300,000 ------------------------------------------------- format_number(2300000 , false) or format_number(2300000 ) Result 2,3m ------------------------------------------------- format_number(180390644 , false) or format_number(180390644 ) Result 180,390,644 Code:
stock format_number(num, bool:only_num = false) |
Re: Number Formatting
Bugsy wrote this function already and it was posted here. I'm quite sure that Bugsy's will be more efficient.
Also, you shouldn't be returning a string, strings should be pass by reference as it is done in function to which I linked. |
Re: Number Formatting
i came across this post while trying to fix something that bothered me days ago
i googled ways to avoid zeros after float numbers and seems like `%g` is not embedded in pawn and a function i did returns something like this https://i.ibb.co/Tb38hZz/image.png i was going to use your thing but some zeros wont hurt after looking the mess you put together Code:
|
Re: Number Formatting
I also have one but mine only supports integers and only adds commas:
PHP Code:
|
Re: Number Formatting
I'm using something in python that might be useful here:
PHP Code:
|
All times are GMT -4. The time now is 10:51. |
Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.