Discuss Scratch

EV2048
Scratcher
33 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:

defineSolveAbbreviationsinputifletterlengthofinputofinput=korletterlengthofinputofinput=morletterlengthofinputofinput=bthenelse

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.

defineSolveAbbreviationsinputifletterlengthofinputofinput=korletterlengthofinputofinput=morletterlengthofinputofinput=bthenelseifinput*input=0thensetreturnedNumbertoinvalid numberelsesetreturnedNumbertoinput

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

defineSolveAbbreviationsinputifletterlengthofinputofinput=korletterlengthofinputofinput=morletterlengthofinputofinput=bthenifletterlengthofinputofinput=kthensetreturnedNumbertoinput*1000ifletterlengthofinputofinput=mthensetreturnedNumbertoinput*1000000ifletterlengthofinputofinput=bthensetreturnedNumbertoinput*1000000elseifinput*input=0thensetreturnedNumbertoinvalid numberelsesetreturnedNumbertoinput

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:

defineSolveAbbreviationsinputifletterlengthofinputofinput=korletterlengthofinputofinput=morletterlengthofinputofinput=bthenelse

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.

defineSolveAbbreviationsinputifletterlengthofinputofinput=korletterlengthofinputofinput=morletterlengthofinputofinput=bthenelseifinput*input=0thensetreturnedNumbertoinvalid numberelsesetreturnedNumbertoinput

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

defineSolveAbbreviationsinputifletterlengthofinputofinput=korletterlengthofinputofinput=morletterlengthofinputofinput=bthenifletterlengthofinputofinput=kthensetreturnedNumbertoinput*1000ifletterlengthofinputofinput=mthensetreturnedNumbertoinput*1000000ifletterlengthofinputofinput=bthensetreturnedNumbertoinput*1000000elseifinput*input=0thensetreturnedNumbertoinvalid numberelsesetreturnedNumbertoinput

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:
defineAbbreviatenumbersetoutputtonumberifnotoutput<1000000000000thensetoutputtooutput/1000000000000setoutputtoroundoutput*100/100setoutputtojoinoutputTstopthis scriptifnotoutput<1000000000thensetoutputtooutput/1000000000setoutputtoroundoutput*100/100setoutputtojoinoutputBstopthis scriptifnotoutput<1000000thensetoutputtooutput/1000000setoutputtoroundoutput*100/100setoutputtojoinoutputMstopthis scriptifnotoutput<1000thensetoutputtooutput/1000setoutputtoroundoutput*100/100setoutputtojoinoutputKstopthis script
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
33 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?
defineTier1-illions12345678910ifnotClicks>999999thensetFinal ProducttoClickselseifnotClicks>999999999thensetFinal ProducttojoinfloorofClicks/1000000000*100/1001elseifnotClicks>999999999999thensetFinal ProducttojoinfloorofClicks/1000000000000*100/1002elseifnotClicks>999999999999999thensetFinal ProducttojoinfloorofClicks/1000000000000000*100/1003elseifnotClicks>999999999999999999thensetFinal ProducttojoinfloorofClicks/1000000000000000000*100/1004
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
33 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
33 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

joinnum/10^offlooroflogofnum+1/3*3itemflooroflogofnum+1/3ofabbreviations

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

joinnum/10^offlooroflogofnum+1/3*3itemflooroflogofnum+1/3ofabbreviations

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

joinnum/10^offlooroflogofnum+1/3*3itemflooroflogofnum+1/3ofabbreviations

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

ifnum>999thensetabbriv. numbtojoinroundnum/10^offlooroflengthofnum-1/3*3itemflooroflengthofnum-1/3ofabbriviationselsesetabbriv. numbtonum

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
33 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

ifnum>999thensetabbriv. numbtojoinroundnum/10^offlooroflengthofnum-1/3*3itemflooroflengthofnum-1/3ofabbriviationselsesetabbriv. numbtonum

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
33 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
33 posts

Help with Number Abbreviations

Just so you don't get confused, I want to find a list-free alternative. Not anything with
lists...
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...

a list free alternative?

idk but this is the best one
ifnumber<orderofmagnitude1thensetnumberabb.tojoinnumber/1000kelseifnumber<orderofmagnitude2thensetnumberabb.tojoinnumber/100000melse. . . so on OoM 2 = 1,000,000 OoM 1 = 1,000 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