ItsDontM
(Java_cup)
February 19, 2022, 6:57am
#1
Hello! I was looking for a script that shorten numbers, but they do not work.I do not understand how to make this system, but I think that the system should be in this script.
I have a local script that gives points.
local Point = Instance.new("IntValue")
Point.Name ="Point"
Point.Value = 0
Point.Parent = script.Parent
script.Parent.MouseMoved:Connect(function()
Point.Value += 1
game.Players.LocalPlayer.PlayerGui.ScreenGui.Change.Text = Point.Value
end)
local Delete = game.Players.LocalPlayer.PlayerGui.ScreenGui.Delete
Delete.MouseButton1Click:Connect(function()
Point.Value = 0
game.Players.LocalPlayer.PlayerGui.ScreenGui.Change.Text = Point.Value
end)
I hope I explained my problem in detail. Good luck and bye!
Did you try searching for similar topics? This has been covered many times already.
ItsDontM
(Java_cup)
February 19, 2022, 10:50am
#3
I searched, but nothing worked.
Forummer
(Forummer)
February 19, 2022, 10:53am
#4
What do you mean by “shorten” numbers? Do you mean round them?
You can use math.floor()
, math.ceil()
, math.round()
to achieve this.
1 Like
These old topics come up just searching for “suffix”:
So I created a number abbreviation system, because I couldn’t seem to find any good ones on youtube or the devforum.
Module With Unnecessary Variables:
local Module = {}
local Abbreviations = {"k", "M", "B", "T", "Qa", "Qn", "Sx", "Sp", "Oc", "N"} -- Number Abbreviations
local f = math.floor --- Rounds down for example 1.99 becomes 1
local l10 = math.log10 -- Checks how many digits are in a number
function Module.AbbreviateNumber(Number: number, Decimals)
return f(((Number < 1 and Number) …
Just use “.Changed” for ValueBase instances (the base class for instances suffixed with the word “Value”, i.e; IntValue, StringValue, NumberValue etc.) it’s more intuitive, like GetPropertyChangedSignal("Value") it only fires when the “Value” property changes and you get the added benefit of the “new value” parameter which represents the new value of the instance’s “Value” property which resulted in the event firing. Take the following for example.
local players = game:GetService("Players")
loc…
I am trying to convert a number into a suffix as well as being able to unpack a suffix.
Example : 1 * 10^6 -> 1M
Example: 1B -> 10^9
The only knowledge I currently know is using if and elseif statements (which would be highly inefficient and unclean) to pack it into a suffix, but I have no clue on how I would be able to unpack a suffix.
Every post is Appreciated!
A simple way to do that is to just get the “magnitude” of the number. Lets say the magnitude of 1234 is “3” and so 10^3 ≈ 1234 since 10^3 = 1000. Then index some suffix array with that magnitude of “3”
I created a “Number” library awhile ago, here is a snippet from it.
function Number.Suffix(Number, Precision)
Precision = Precision or 0
local Suffixes = {
"", "K","M", "B", "T",
"Qa", "Qi", "Sx", "Sp",
"Oc", "No", "Dc", "Ud",
…
You can try converting it to a string and abbreviating it that way. A common module I’ve seen recommended is the one berezaa made for Miner’s Haven. Here’s his MoneyLib module:
(The relevant function is called “shorten”.)
What have you tried so far and how didn’t it do what you want?
The basic idea is to use math.log
math to get the base 10 logarithm of the number, which tells you how many digits are in the number. You then floor that number and look through a table to see which metric prefix fits best. Then divide the number by the size of the prefix and add the relevant prefix/suffix.
1 Like
ItsDontM
(Java_cup)
February 19, 2022, 11:41am
#6
How do I get this to work? I have a text that changes to a number when I move the mouse over a gui.
I found one script, but I don’t understand how to make it work.
ItsDontM
(Java_cup)
February 19, 2022, 12:03pm
#7
Okay, I think I don’t need it.Thanks for the help.
1 Like