A Way to Easily Format Numbers

As a Roblox developer, it is currently too hard to format numbers that support localization through code. Today I began translating a project of mine for the first time and I hit a roadblock when it came to translating formatted numbers. You see, AutoLocalize works really well in most scenarios, but there are some cases where it just won’t work.

All I wanted to do was translate a sole number that contained thousand seperators. It sounds simple at first. However, as of right now, translating a number through code requires developers to use :FormatByKey(). See the issue yet?

To use this method I would need to add a source entry in the translator portal such as {1:num} with a key. And for each translated language, the translation would be a duplicate: {1:num}. This right off the bat sounds extremely tedious because if you forget to add the duplicate “translation,” the numbers will be in the source language’s format. That’s not all though.

Let’s say I did go through all that work to translate a number, I still have other issues that I cannot solve. This time however, I will list the issues that come up while formatting the number:

  • There is no proper way to format a localized number with thousand separators and without decimals. This means space is wasted on decimals that are unnecessary and it can also confuse visitors.

  • Sometimes a big number needs to be shortened through something like abbreviations (ex. 100k). This is currently not possible with the current localization support.

  • Occasionally numbers need to be spelled out (ex. a check from a bank). This is another number format that is not possible with the current localization support.

  • There is no way to control how many decimals a translated number can have.

  • There is no way to support ordinal numbers that are localized with ease (ex. 1st, first).

I am indeed emphasizing the localization support for number formatting because I do believe it is extremely important when formatting numbers for visitors. The DateTime object does an extremely good job at making it easy for developers to format and localize both time and dates. I believe one of the next steps for making it easier for developers to localize their experiences is by introducing a way to easily format numbers.

If Roblox is able to address this issue, it would improve my development experience because I wouldn’t need to worry about if the format of the numbers within my experiences hinder the visitors that visit them. My experience would also be improved because I wouldn’t need to support a language through the translator portal to have the proper number format for my visitors. Thank you.

11 Likes

Should it be in the shortest decimal representation (like most number formatter library) or should it be in exact representation?

This is NOT a trivial operation. I personally would suggest to port ICU to Roblox but I don’t see that happening anytime soon.

How does it sound simple? You have to deal with Infinity and NaN (more than one types!), with a decision of whether subnormal numbers should be formatted as zero or not (because it is inconsistent, tostring prints it as 0).

Why call it “shortened”?
Why not compact notation?
What about long compact notation?
Why diverge from the most common standard pattern for English by formatting it as 100k instead of 100K?

How would this work without Precision class?
Why call it “decimals”? Why not call it fractional digits like most other formatting library.
Why not include significant digits?
What about nearest integer keeping two significant digits with no trailing zeroes?


This can all be solved using ICU.

The DateTime object for some reason don’t have POSIX locales nor quarters.
It also only supports Gregorian calendars.

In no way is translating numbers a trivial operation. Hence the feature request’s title and the request itself.

Roblox already provides a way to translate/format numbers (in limited formats, etc), hence why it “sounds simple at first.” After that sentence I go on to explain why it sounded simple to begin with and why it isn’t “simple.” In no way does it “sound simple” if I was the one doing the implementation of formatting and translating numbers.

I’m not exactly sure why you’re asking this? I am no number expert and do not know number jargon. I am merely discussing a problem in layman terms.

This feature request, like one should, goes over only the problems and use cases for the feature request. It does not suggest nor propose a solution because the instructions on how to make one says (or recommends) to not focus on the solution.

7 Likes