mirror of
https://github.com/PlaceholderAPI/Javascript-Expansion.git
synced 2025-05-24 20:02:44 +00:00
Added Suffix Format
parent
936a99dafd
commit
53bf25e9a2
@ -1160,3 +1160,41 @@ numInGroupOfWorlds();
|
|||||||
number_in_group_of_worlds:
|
number_in_group_of_worlds:
|
||||||
file: number_in_group_of_worlds.js
|
file: number_in_group_of_worlds.js
|
||||||
```
|
```
|
||||||
|
|
||||||
|
***
|
||||||
|
|
||||||
|
### Suffix Format
|
||||||
|
* **Author:** cj89898
|
||||||
|
* **Description:** Formats numbers to a shortened version with a suffix. Suffixes and Decimals can both be customized.
|
||||||
|
* **Usage:** `%javascript_suffixFormat_<raw number>%` - Can use placeholders surrounded by `{}`
|
||||||
|
* **Example:** `%javascript_suffixFormat_{vault_eco_balance}%` could return `1.89S`
|
||||||
|
|
||||||
|
**Save as** `suffixFormat.js`
|
||||||
|
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
var num = Number(args[0]);
|
||||||
|
|
||||||
|
function formatNum(num){
|
||||||
|
var suffixes = ['', 'k', 'm', 'b', 't', 'qd', 'qn', 's']; //More Suffixes: 'sp', 'o', 'n', 'd', 'ud', 'dd', 'td'
|
||||||
|
var decimals = 2;
|
||||||
|
for(i=0;i<suffixes.length;i++){
|
||||||
|
if(num>=1000){
|
||||||
|
num = (num/1000);
|
||||||
|
} else {
|
||||||
|
return num.toFixed(decimals)+suffixes[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return (num*1000).toFixed(decimals)+suffixes[suffixes.length-1];
|
||||||
|
}
|
||||||
|
|
||||||
|
formatNum(num);
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
**Add to** `javascript_placeholders.yml`
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
suffix_format:
|
||||||
|
file: suffixFormat.js
|
||||||
|
```
|
Loading…
x
Reference in New Issue
Block a user