Solved How can I display a number as money value?

  • 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!

Status
Not open for further replies.

MartinOdum

Member
Jan 26, 2017
112
13
18
For the longest time this has bothered me but I have never exactly found a solution to it, basically I have tons of economy related scripts in which players get paid and usually this means I send them a message in chat that tells them how much they earned, a super basic example below:

code_language.skript:
command /test:
    trigger:
        set {_money} to 2.50
        add {_money} to player's balance
        send "You have earned %{_money}%" to player

The problem is in chat, zeros after a decimal are not displayed, this means that 2.50 is displayed as 2.5 in chat, 2.00 would be displayed as 2 etc, this is just tedious since I'd like everything to be displayed correctly as money, I have tried a few things such as parsing {_money} as money but no luck there, I also tried parsing it as text but no luck there either, I just thought I'd reach out for help on the forums and see if anyone has any ideas?

Sidenote: I am aware of the "number accuracy:" option in the skript config, I have it set to 2 but like it says:
"Zeroes will never be displayed at all, so this setting only applies to numbers that actually have a decimal part with one or more non-zero digits."
I also noticed it also says:
"Money bypasses this setting and is displayed as configured in your economy plugin if you have one."

But like I said when I parse the value as money it still shows it as 2.5
 
Try this, untested.

code_language.skript:
command /test:
    trigger:
        set {_money} to 2.50
        set {_money} to {_money} parsed as number
        add {_money} to player's balance
        send "You have earned %{_money}%" to player
 
Try this, untested.

code_language.skript:
command /test:
    trigger:
        set {_money} to 2.50
        set {_money} to {_money} parsed as number
        add {_money} to player's balance
        send "You have earned %{_money}%" to player
Same result
 
code_language.skript:
command /test:
    trigger:
        set {_money} to "2.50"
        add {_money} parsed as a number to player's balance
        send "You have earned %{_money}%" to player
 
code_language.skript:
command /test:
    trigger:
        set {_money} to "2.50"
        add {_money} parsed as a number to player's balance
        send "You have earned %{_money}%" to player
Uhm, so the thing is this would probably be a direct fix for the specific code, what I'm looking for is for a way to display a number variable as money value because in alot of my scripts I don't have a specific amount to pay someone, for example lets say I have a fishing shop and I pay people 0.50 per fish, in the script I have to do
set {_amount} to amount of raw fish in player's inventory
and then I would do,
set {_payout} to {_amount}*2.50
and now what I have is basically {_payout} is always different depending on how many fish the player had, this means in my scripts I don't have an exact number from the start so I can't exactly do what you did
 
Uhm, so the thing is this would probably be a direct fix for the specific code, what I'm looking for is for a way to display a number variable as money value because in alot of my scripts I don't have a specific amount to pay someone, for example lets say I have a fishing shop and I pay people 0.50 per fish, in the script I have to do
set {_amount} to amount of raw fish in player's inventory
and then I would do,
set {_payout} to {_amount}*2.50
and now what I have is basically {_payout} is always different depending on how many fish the player had, this means in my scripts I don't have an exact number from the start so I can't exactly do what you did

Try

code_language.skript:
set {_payout} to ({_amount} parsed as a number to player's balance) * 2.50
 
You can change that going to the config.sk in the Skript folder at your plugins folder, then search the "number accuracy" option and change it to how much decimal places you want it to display, for example, you want it to display 2.50 you would change it to 2, if you want it to display 2.5643, you would change it to 4.
 
You can change that going to the config.sk in the Skript folder at your plugins folder, then search the "number accuracy" option and change it to how much decimal places you want it to display, for example, you want it to display 2.50 you would change it to 2, if you want it to display 2.5643, you would change it to 4.
I actually have it set to 2 at the moment, the config option actually states that it excludes zeros which sucks because otherwise it would fix my issue


Edit: So as I guessed I don't think there is a simple solution to this, simply changing a config value or using a specific effect etc wont seem to do the trick (correct me if I'm wrong) so I went ahead and just made a function that will return a number back in money form, I'm not claiming my function is the best method to go about this so if you have a better way/better function then feel free to show it off but this is what I came up with

code_language.skript:
function moneyvalue(n: number) :: text:
    if "%{_n}%" does not contain ".":
        return "%{_n}%.00"
    else:
        set {_s::*} to split "%{_n}%" at "."
        if length of {_s::2} is equal to 1:
            return "%{_n}%0"
        else:
            return "%{_n}%"

example usage:

code_language.skript:
command /test:
    trigger:
        set {_money1} to 1
        set {_money2} to 1.00
        set {_money3} to 1.50
        send "1 is normally displayed as %{_money1}%" and "With function: %moneyvalue({_money1})%" and "1.00 is normally displayed as %{_money2}%" and "With function: %moneyvalue({_money2})%" and "1.50 is normally displayed as %{_money3}%" and "With function: %moneyvalue({_money3})%"
 
Last edited by a moderator:
Status
Not open for further replies.