1000 TO 1K

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

    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.

Narek7445

Member
May 12, 2019
4
0
1
27
How to make 1000 to 1k
Like
1000 = 1k
1000000 = 1M
1000000000 = 1B
1000000000000 = 1T
1000000000000000 = 1Qn
1000000000000000000 = 1Qi
1000000000000000000000 = 1Sx
 
Code:
if {test} is 1000:
    set {test} to "1k"
and the numbers are the same format.
 
How to make 1000 to 1k
Like
1000 = 1k
1000000 = 1M
1000000000 = 1B
1000000000000 = 1T
1000000000000000 = 1Qn
1000000000000000000 = 1Qi
1000000000000000000000 = 1Sx
code_language.skript:
set {_balance} to player's balance
if {_balance} is between 1000 and 9999:
    send "&aYour balance is: %first character of {_balance}%K"
else if {_balance} is between 10000 and 99999:
    send "&aYour balance is: %first 2 characters of {_balance}%K"
else if {_balance} is between 100000 and 999999:
    send "&aYour balance is: %first 3 characters of {_balance}%K"
else if {_balance} is between 1000000 and 9999999:
    send "&aYour balance is: %first character of {_balance}%M"
#And you do that up to the limit number.
[doublepost=1557710616,1557710509][/doublepost]
Code:
if {test} is 1000:
    set {test} to "1k"
and the numbers are the same format.
That is wrong. Because in the variable you wrote:
code_language.skript:
if {test} is 1000:
but after you wrote the variable as text:
code_language.skript:
set {test} to "1K"
 
Last edited:
  • Like
Reactions: Bap_Ehh
This is how I always did it:

code_language.skript:
set {_bal} to balance of player
if {_bal} is between 1000 and 999999:
    set {_new} to "%{_bal}/1000%K"
else if {_bal} is between 1000000 and 999999999:
    set {_new} to "%{_bal}/1000000%M"
#etc
message {_new} to player
 
I think
Code:
function formatNum(n: number) :: string:
    set {_l::*} to split "k,M,B,T,Qn,Qi,Sx" at ","
    set {_i} to min(floor(log({_n})/3), size of {_l::*})
    return "%{_n}%" if {_i} <= 0
    set {_i2} to 1000^{_i}
    return "%{_n}/{_i2}%%{_l::%{_i}%}%"
would work
 
Last edited:
this is much more efficient:
code_language.skript:
set {_v::*} to 1000, 1000000, 1000000000
set {_n::*} to "K", "M" and "B"
set {_b} to balance of player
loop {_v::*}:
    {_b} > loop-value
    set {_r} to "%{_b} / loop-value%%{_n::%loop-index%}%"
send "&aBalance: &c%{_r}%"
 
this is much more efficient:
code_language.skript:
set {_v::*} to 1000, 1000000, 1000000000
set {_n::*} to "K", "M" and "B"
set {_b} to balance of player
loop {_v::*}:
    {_b} > loop-value
    set {_r} to "%{_b} / loop-value%%{_n::%loop-index%}%"
send "&aBalance: &c%{_r}%"
Mine is more efficient :emoji_stuck_out_tongue:
 
I think
code_language.skript:
function formatNum(n: number) :: string:
    set {_l::*} to split "k,M,B,T,Qn,Qi,Sx" at ","
    set {_i} to min(floor(log({_n})/3), size of {_l::*})
    return "%{_n}%" if {_i} <= 0
    set {_i2} to 1000^{_i}
    return "%{_n}/{_i2}%%{_l::%{_i}%}%"
would work
Yea def more efficient. Usually things without loops are more efficient in my opinion.
 
Status
Not open for further replies.