NumberSpinner Module

Can you add support for commas?

4 Likes

Massive Update!

Complete rewrite and refactor


This update exposes all the properties of a TextLabel as top-level members of Spinner. This means that you no longer have to do Spinner.Frame.Size but rather just Spinner.Size! Much cleaner. it also means that all the properties are supported instead of just font, size, and color. Now you can have textstrokes and stuff too!

This update also adds a new creator method: NumberSpinner.fromGuiObject(GuiObject)! This will create a Spinner and automatically apply the properties of the passed GuiObject. If the GuiObject is a TextObject, it will also apply the text related properties.

I’ve added a setting Spinner.Commas as per @AlreadyPro’s request.
I’ve also added Spinner.Suffix which is the same as prefix but at the end.

I’ve added support for negative values (somehow we never noticed that negative values errored?) so that works now!

11 Likes

For some reason it’s not changing the decimal symbol to comma.
Anyway, what a great, unambiguous, explicit and featured API, it’s more explicit and less ambiguous than ICU’s API I say. I totally was confused by ICU’s API. Let’s switch from groupingStrategy to Commas. Also let’s switch from ‘AUTO’, ‘OFF’, ‘MIN2’, ‘ON_ALIGNED’ and ‘THOUSANDS’ to booleans for this, totally gave me more option and is less ambiguous. Let’s default this value to false instead of being notation sensitive (MIN2 for compact, AUTO for everything else). Thanks for the inspiration /s

In seriousness, maybe have a less ambiguous name than “commas”?

and still errors for other IEEE 754 values like Infinites & NaNs which I pointed out. Maybe a more friendly error message for values like this?
Checking the source code.

local isNegative = Spinner.Value < 0

What’s this amazing algorithm you got there? You’re very talented indeed. You found a new way to check for signed value.
Now instead of dividing by the value just to see if it’s Infinity/-Infinity if it equals to 0 and checking for sign bit for NaNs, I could now check for negative NaN (no difference between a positive NaN except visual and sign bit manipulation) using this algorithm. Thanks to this feature, I learnt that the - sign suddenly disappeared when a floating point underflow has occurred, 1 divided by value totally doesn’t return signed Infinity but positive Infinity /s.

In seriousness this doesn’t account for signed 0 which I’m not sure if it’s also intentional, (though floats close to signed 0 like -1e-100 returns signed 0).


Is this also intended to be an alternative for the NumberFormatter from ICU? With ‘Commas’ and Currencies added, it’s kinda feels like it sans i18n-related stuff.

2 Likes

Nice looking NumberSpinners! Well, as I am a person who makes visualization, I used to make it once…
https://i.gyazo.com/4fc0fb6156b8fc5daf7b6535d7ff301b.mp4

But it’s looking pretty neat. Nice one!

2 Likes

Is it possible to reverse the transition from a 10 → 9?

Show in this GIF, my timer counts down from 10 to 0, but the first transition has it go from 10 → 0 → all the way back to 9 which makes it look odd compared to the following transitions

If you do feel like updating this, a setting called something like ReverseOnDigitChange (idk) would be cool
https://gyazo.com/c2ea9978a243fdf7365389b40a5cf6d2

4 Likes

This module does not seem to work with the TextScaled property. From my own tests when creating a new spinner object with .fromGuiObject the text size will be whatever size is set in the text properties.

Likewise, when trying to manually set the TextScaled property to true via mySpinner.TextScaled = true also does not scale the text to the frame size. (Obviously, if you look at the instance created in the playerGui you will see this wouldn’t work)

Unless I am getting something wrong, this isn’t usable as-is if you want your game to be viewable on a wide variety of screen sizes, such as phones.

On that note, does anyone know how to make this work wth scaled text and/or know of another module that can do this with scaled text?

1 Like

Your comment inspired me to recreate that game the next night, and then I completely forgot to mention or release it lol

The game is now a nice example of this module being used in a full game environment!
https://www.roblox.com/games/6528148945/Money-Makin-Machine

6 Likes

This Spinner Module is pretty nice, but there is one problem. The fromGuiObject function doesn’t work as I expected, the UI Gradient inside the original GuiObject doesn’t get added in the Spinner, the sizing gets very altered and some digits dont have the same stroke configuration as the original GuiObject (some digits have a stroke and some don’t).

2 Likes

How would I use this to create a clock and be able to have a : so I could have it in a usual time format.

1 Like

How can I make this work with Roact?

2 Likes

A great addition that is similar to Decimals/Commas would be to be able to support time string so we can do things like a timer:
“2:00”
“1:59”
“0:30”

Other than that, nice module.

4 Likes

Nice module! It’s such a good module for little touches in your game. Can’t wait to see what comes next!

2 Likes

Pretty neat module, but had a question. Is there a way to remove the .00 after the actual number? It’s a little annoying.

EDIT: Nevermind, just figured it out that you can remove it by setting Decimals to 0.

1 Like

Pretty Cool Module but why are the numbers so small?


image

second pic is the size I would want it to be
code is just basically this:


local NumberSpinner = require(script:WaitForChild("NumberSpinner"))

local Frame = script.Parent:WaitForChild("Frame")

local Spinner = NumberSpinner.fromGuiObject(Frame.TextLabel)
Spinner.Decimals = 0 
Spinner.Parent = Frame


while wait(0.5)  do
	Spinner.Value = math.random(1,1000000)	
end

any help will do!

2 Likes

I dont think it works with the TextScaled property.

2 Likes

do you know how to make the spinner bigger?

1 Like

Just set the TextLabel’s TextSize property to a bigger number?

2 Likes

Wait can anyone explain how I can set this up? I’m a lil confused

1 Like

Hello, I just have a few questions.

  1. How can i make it use an already existing label, if that is even possible
  2. What am i doing wrong here -
local Players        = game:GetService("Players") 
local Replicated     = game:GetService("ReplicatedStorage")

local Player         = Players.LocalPlayer
local Cash           = Player:WaitForChild("leaderstats").Cash
local Label          = script.Parent
local NumberSpinner  = require(Replicated:WaitForChild("NumberSpinner"))

local PriceSpinner = NumberSpinner.new()
PriceSpinner.Decimals = 0
PriceSpinner.Duration = 0.25
PriceSpinner.Parent = Label

Cash.Changed:Connect(function()
	PriceSpinner.Value =("$"..Cash.Value)
end)

Just throws this

Attempted to set Spinner.Value to invalid value ($49)
1 Like

Value needs to be a number, not a string. You can set the spinner prefix to $ if you’d like.

1 Like