Solved Format currency

  • Welcome to skUnity!

    Welcome to skUnity! This is a forum where members of the Skript community can communicate and interact. Skript Resource Creators can post their Resources for all to see and use.

    If you haven't done so already, feel free to join our official Discord server to expand your level of interaction with the community!

    Now, what are you waiting for? Join the community now!

  • LOOKING FOR A VERSION OF SKRIPT?

    You can always check out skUnity Downloads for downloads and any other information about Skript!

Vini

Member
Apr 8, 2023
42
2
8
I've found a few posts about currency formatting, but I couldn't add them to my code
This is my code
Code:
command /withdraw <number> [<number>]:
    trigger:
        if arg-2 is not set:
            if player's balance >= arg-1:
                remove arg-1 from balance of player
                give player bamboo named "&aMoney Roll &8[&a$%arg-1%&8]" with lore "&fRight-Click to redeem" and "&7Rarity &a&lMONEY"
Now here: "give player bamboo named "&aMoney Roll &8[&a$%arg-1%]" with lore "&fRight-Click to redeem" and "&7Rarity &a&lMONEY" I'd like to format the arg-1 part to be like 1000: 1,000 | 10000: 10,000 | 100000: 100,000 etc.

I have no idea how I could start.
Can someone help?
 
Last edited:
Code:
function regex(n: object) :: text:
    if "%{_n}%" contains ".":
        set {_s::*} to split "%{_n}%" at "."
        set {_n} to "%a({_s::1})%.%last 2 characters of {_s::2}%"
        return "%{_n}%"
    else:
        set {_n} to a("%{_n}%")
        return "%{_n} ? 0%"

function a(b: text) :: text:
    if length of {_b} > 3:
        return "%a(first length of {_b} - 3 characters of {_b})%,%last 3 characters of {_b}%"
    return {_b}

The usage will be "&aMoney Roll &8[&a$%regex(arg-1)%&8]"
 
Code:
function regex(n: object) :: text:
    if "%{_n}%" contains ".":
        set {_s::*} to split "%{_n}%" at "."
        set {_n} to "%a({_s::1})%.%last 2 characters of {_s::2}%"
        return "%{_n}%"
    else:
        set {_n} to a("%{_n}%")
        return "%{_n} ? 0%"

function a(b: text) :: text:
    if length of {_b} > 3:
        return "%a(first length of {_b} - 3 characters of {_b})%,%last 3 characters of {_b}%"
    return {_b}

The usage will be "&aMoney Roll &8[&a$%regex(arg-1)%&8]"
Thank you so much! It worked!