Discuss Scratch

EV2048
Scratcher
44 posts

Help with Number Abbreviations

Can anyone help me with number abbreviations? Like 1000=1k, 1000000=1m, etc.
TheOpalofTopaz
Scratcher
100+ posts

Help with Number Abbreviations

EV2048 wrote:

Can anyone help me with number abbreviations? Like 1000=1k, 1000000=1m, etc.
Sadly, there is another forum like this I believe. I won't report it as an exception!
souleymane2
Scratcher
100+ posts

Help with Number Abbreviations

Hey there,

If you want to work on number abbreviations we're going to use parsing.

Lets start by checking if the last letter is either k (thousand) m (million) or b (billion). We can do so by taking advantage of the length of string block:

define SolveAbbreviations (input)
if <<(letter (length of (input)) of (input)) = [k]> or <<(letter (length of (input)) of (input)) = [m]> or <(letter (length of (input)) of (input)) = [b]>>> then

else

end

If thats not the case then well make sure it is indeed a number. To do so, were going to square it. If it returns a 0 then we know its incorrect as no numbers squares return 0.

define SolveAbbreviations (input)
if <<(letter (length of (input)) of (input)) = [k]> or <<(letter (length of (input)) of (input)) = [m]> or <(letter (length of (input)) of (input)) = [b]>>> then

else
if <((input) * (input)) = [0]> then
set [returnedNumber v] to [invalid number]
else
set [returnedNumber v] to (input)
end
end

Ok perfect. Now lets get to work. If the value is k then we want to multiply it by 1000. If its m then we want to multiply it by 1000000. And finally if its b we multiply it by 1000000000

define SolveAbbreviations (input)
if <<(letter (length of (input)) of (input)) = [k]> or <<(letter (length of (input)) of (input)) = [m]> or <(letter (length of (input)) of (input)) = [b]>>> then
if <(letter (length of (input)) of (input)) = [k]> then
set [returnedNumber v] to ((input) * (1000))
end
if <(letter (length of (input)) of (input)) = [m]> then
set [returnedNumber v] to ((input) * (1000000))
end
if <(letter (length of (input)) of (input)) = [b]> then
set [returnedNumber v] to ((input) * (1000000))
end
else
if <((input) * (input)) = [0]> then
set [returnedNumber v] to [invalid number]
else
set [returnedNumber v] to (input)
end
end

Hope this helps!
SpyCoderX
Scratcher
1000+ posts

Help with Number Abbreviations

souleymane2 wrote:

Hey there,

If you want to work on number abbreviations we're going to use parsing.

Lets start by checking if the last letter is either k (thousand) m (million) or b (billion). We can do so by taking advantage of the length of string block:

define SolveAbbreviations (input)
if <<(letter (length of (input)) of (input)) = [k]> or <<(letter (length of (input)) of (input)) = [m]> or <(letter (length of (input)) of (input)) = [b]>>> then

else

end

If thats not the case then well make sure it is indeed a number. To do so, were going to square it. If it returns a 0 then we know its incorrect as no numbers squares return 0.

define SolveAbbreviations (input)
if <<(letter (length of (input)) of (input)) = [k]> or <<(letter (length of (input)) of (input)) = [m]> or <(letter (length of (input)) of (input)) = [b]>>> then

else
if <((input) * (input)) = [0]> then
set [returnedNumber v] to [invalid number]
else
set [returnedNumber v] to (input)
end
end

Ok perfect. Now lets get to work. If the value is k then we want to multiply it by 1000. If its m then we want to multiply it by 1000000. And finally if its b we multiply it by 1000000000

define SolveAbbreviations (input)
if <<(letter (length of (input)) of (input)) = [k]> or <<(letter (length of (input)) of (input)) = [m]> or <(letter (length of (input)) of (input)) = [b]>>> then
if <(letter (length of (input)) of (input)) = [k]> then
set [returnedNumber v] to ((input) * (1000))
end
if <(letter (length of (input)) of (input)) = [m]> then
set [returnedNumber v] to ((input) * (1000000))
end
if <(letter (length of (input)) of (input)) = [b]> then
set [returnedNumber v] to ((input) * (1000000))
end
else
if <((input) * (input)) = [0]> then
set [returnedNumber v] to [invalid number]
else
set [returnedNumber v] to (input)
end
end

Hope this helps!
That won’t work.

What you will actually want to do is make another variable as the output we can have the actual value stay the same.

So, to make the abbreviated number:

First, check how big the number is.

Example: >=1000 we use K as the abbreviation

Then, we divide the number by a power of 10 based on the previous check.
For >=1000 we use 1000

Now, we can round the number down to 2 digits after the decimal place (1.00)

Note: >= is the same as not(<)

Full code:
define Abbreviate (number)
set [output v] to (number)
if <not<(output)<(1000000000000)>> then
set [output v] to ((output)/(1000000000000))
set [output v] to ((round((output)*(100)))/(100))
set [output v] to (join (output) (T))
stop [this script v]
end
if <not<(output)<(1000000000)>> then
set [output v] to ((output)/(1000000000))
set [output v] to ((round((output)*(100)))/(100))
set [output v] to (join (output) (B))
stop [this script v]
end

if <not<(output)<(1000000)>> then
set [output v] to ((output)/(1000000))
set [output v] to ((round((output)*(100)))/(100))
set [output v] to (join (output) (M))
stop [this script v]
end

if <not<(output)<(1000)>> then
set [output v] to ((output)/(1000))
set [output v] to ((round((output)*(100)))/(100))
set [output v] to (join (output) (K))
stop [this script v]
end
warriorcatsfreakalt
Scratcher
1000+ posts

Help with Number Abbreviations

TheOpalofTopaz wrote:

EV2048 wrote:

Can anyone help me with number abbreviations? Like 1000=1k, 1000000=1m, etc.
Sadly, there is another forum like this I believe. I won't report it as an exception!
Duplicate topics don't really matter in the Help with Scripts section, I believe. They're only an issue in the Suggestions, I think.
SpyCoderX
Scratcher
1000+ posts

Help with Number Abbreviations

warriorcatsfreakalt wrote:

TheOpalofTopaz wrote:

EV2048 wrote:

Can anyone help me with number abbreviations? Like 1000=1k, 1000000=1m, etc.
Sadly, there is another forum like this I believe. I won't report it as an exception!
Duplicate topics don't really matter in the Help with Scripts section, I believe. They're only an issue in the Suggestions, I think.
There is one case where duplicates still exist in HWS. If the same user creates 2 topics for the same issue, those are duplicates.
EV2048
Scratcher
44 posts

Help with Number Abbreviations

Before I even saw all these posts, I finally figured it out! But can you help me with going over the quadrillions?
define Tier 1 -illions(1)(2)(3)(4)(5)(6)(7)(8)(9)(10)
if<not<(Clicks) > (999999)>>then
set[Final Product v]to(Clicks)
else
if<not<(Clicks) > (999999999)>>then
set[Final Product v]to(join([floor v]of((Clicks)/1000000000)*(100))/(100)(1))
else
if<not<(Clicks) > (999999999999)>>then
set[Final Product v]to(join([floor v]of((Clicks)/1000000000000)*(100))/(100)(2))
else
if<not<(Clicks) > (999999999999999)>>then
set[Final Product v]to(join([floor v]of((Clicks)/1000000000000000)*(100))/(100)(3))
else
if<not<(Clicks) > (999999999999999999)>>then
set[Final Product v]to(join([floor v]of((Clicks)/1000000000000000000)*(100))/(100)(4))
end
end
end
end
end
Then it just goes to the exponents.

Last edited by EV2048 (Sept. 1, 2024 16:55:16)

EpicGhoul993
Scratcher
1000+ posts

Help with Number Abbreviations

Loop-based solution, with negative number support.

Yeah, it feels like the entire topic forgot about loops or something.
EV2048
Scratcher
44 posts

Help with Number Abbreviations

EpicGhoul993 wrote:

Loop-based solution, with negative number support.

Yeah, it feels like the entire topic forgot about loops or something.
I'm trying to make a clicker game, not like an ask and answer thing.
EV2048
Scratcher
44 posts

Help with Number Abbreviations

I think I solved the problem!
https://scratch.mit.edu/projects/1067849190
codeywhizz
Scratcher
100+ posts

Help with Number Abbreviations

https://scratch.mit.edu/projects/1067575984/

This project by this insanely handsome, talented, and smart scratcher seems to sort ur problem, click space to run, and also consider dropping a follow if it helped
bsteichman
Scratcher
500+ posts

Help with Number Abbreviations

here is a one liner that does this made by yours truly

have a list with the abbreviations in order EX:k,m,b,t

(join ((num) / ([10^ v] of (([floor v] of (([log v] of ((num) + (1))) / (3))) * (3)):: operators)) (item ([floor v] of (([log v] of ((num) + (1))) / (3))) of [abbreviations v] :: list))

or drag the code from my project into your backpack!

Last edited by bsteichman (Sept. 14, 2024 20:25:44)

EpicGhoul993
Scratcher
1000+ posts

Help with Number Abbreviations

EV2048 wrote:

I'm trying to make a clicker game, not like an ask and answer thing.
So, like, just replace the ask and answer with your game code?????? Do you expect me to make an entire clicker to go with it?
codeywhizz
Scratcher
100+ posts

Help with Number Abbreviations

bsteichman wrote:

here is a one liner that does this made by yours truly

have a list with the abbreviations in order EX:k,m,b,t

(join ((num) / ([10^ v] of (([floor v] of (([log v] of ((num) + (1))) / (3))) * (3)):: operators)) (item ([floor v] of (([log v] of ((num) + (1))) / (3))) of [abbreviations v] :: list))

or drag the code from my project into your backpack!
will this work for scientific form tho? log becomes slightly inaccurate when put to massive numbers in java and scratch, causing ur calculations to go off

Last edited by codeywhizz (Sept. 15, 2024 09:40:39)

bsteichman
Scratcher
500+ posts

Help with Number Abbreviations

codeywhizz wrote:

bsteichman wrote:

here is a one liner that does this made by yours truly

have a list with the abbreviations in order EX:k,m,b,t

(join ((num) / ([10^ v] of (([floor v] of (([log v] of ((num) + (1))) / (3))) * (3)):: operators)) (item ([floor v] of (([log v] of ((num) + (1))) / (3))) of [abbreviations v] :: list))

or drag the code from my project into your backpack!
will this work for scientific form tho? log becomes slightly inaccurate when put to massive numbers in java and scratch, causing ur calculations to go off

accurate to the first few digits, which is usually all you need. i doubt anyone that wants a number shortener wants like 1.327474983749387decillion they prolly would want just like 1.328 decillion.
in my project, i have a way to round it to however many decimals as well.
happywaffle0
Scratcher
100+ posts

Help with Number Abbreviations

EV2048 wrote:

Can anyone help me with number abbreviations? Like 1000=1k, 1000000=1m, etc.

first, make a list on number abbreviations (dw I gotchu for some)
k, m, b, t, Qd, Qi, Sx ,Sp, Oc, No, D, UnD, DuD, TrD, QdD, QiD SxD SpD OcD NovD v… then so on
at the same time you could make the number abbrivation word thing full

then make a script (simplest form) like this

if <(num) > (999)> then
set [abbriv. numb v] to (join (round((num) / ([10^ v] of ([floor v] of ((((length of (num)) - (1)) / (3)) * (3))::operators))) (item ([floor v] of ((((length of (num)) - (1)) / (3)))) of [abbriviations v] :: list)
else
set [abbriv. numb v] to (num)
end

it appears the block is tooooooo long. use shift+arrow to view entire thing.

Last edited by happywaffle0 (Sept. 17, 2024 00:41:09)

EV2048
Scratcher
44 posts

Help with Number Abbreviations

happywaffle0 wrote:

EV2048 wrote:

Can anyone help me with number abbreviations? Like 1000=1k, 1000000=1m, etc.

first, make a list on number abbreviations (dw I gotchu for some)
k, m, b, t, Qd, Qi, Sx ,Sp, Oc, No, D, UnD, DuD, TrD, QdD, QiD SxD SpD OcD NovD v… then so on
at the same time you could make the number abbrivation word thing full

then make a script (simplest form) like this

if <(num) > (999)> then
set [abbriv. numb v] to (join (round((num) / ([10^ v] of ([floor v] of ((((length of (num)) - (1)) / (3)) * (3))::operators))) (item ([floor v] of ((((length of (num)) - (1)) / (3)))) of [abbriviations v] :: list)
else
set [abbriv. numb v] to (num)
end

it appears the block is tooooooo long. use shift+arrow to view entire thing.
Or use quote to view the entire thing in text.
EV2048
Scratcher
44 posts

Help with Number Abbreviations

TheOpalofTopaz wrote:

EV2048 wrote:

Can anyone help me with number abbreviations? Like 1000=1k, 1000000=1m, etc.
Sadly, there is another forum like this I believe. I won't report it as an exception!
Which one is it?
EV2048
Scratcher
44 posts

Help with Number Abbreviations

Just so you don't get confused, I want to find a list-free alternative. Not anything with
 (lists...::list) 
happywaffle0
Scratcher
100+ posts

Help with Number Abbreviations

EV2048 wrote:

Just so you don't get confused, I want to find a list-free alternative. Not anything with
 (lists...::list) 

a list free alternative?

idk but this is the best one
if <(number) < (order of magnitude 1)> then // OoM 1 = 1,000 
set [numberabb. v] to (join ((number) / (1000)) (k))
else
if <(number) < (order of magnitude 2)> then // OoM 2 = 1,000,000
set [numberabb. v] to (join ((number) / (100000)) (m)
else
... // so on
end
end

//note each order of magnitude is a power of 1000 (e.g. OoM 5 = quintillion)

Last edited by happywaffle0 (Sept. 25, 2024 12:14:00)

Powered by DjangoBB