You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The Unicode Technical Standard specifies a list of long and short Compact Number Formats for use in formatting truncated versions of numbers (e.g. 35K, 2M). For reference, the JSON representation of these formats in English can be viewed here. x/text implements a lot of the standard, including currency and number formatting, but there isn't currently a way to get compact formats as described.
I suggest x/text/number be given a CompactOption which can be created with either a "long" or "short" typed argument. When this option is provided and the number formatted is suitable for compacting in that locale, the compact version should instead be returned.
The text was updated successfully, but these errors were encountered:
The infrastructure to parse and organize the needed data is present in x/text's internal packages.
I would just not make it an option, but rather a Formatter. This way formatting w compact number would read:
p := message.NewPrinter(language.English)
p.Printf("%v bottles of beer on the wall.", number.Compact(3000000))
// Prints: 3M bottles of beer on the wall.
This would default to english printing when used with the fmt package.
The Unicode Technical Standard specifies a list of long and short Compact Number Formats for use in formatting truncated versions of numbers (e.g. 35K, 2M). For reference, the JSON representation of these formats in English can be viewed here.
x/text
implements a lot of the standard, including currency and number formatting, but there isn't currently a way to get compact formats as described.I suggest
x/text/number
be given aCompact
Option which can be created with either a "long" or "short" typed argument. When this option is provided and the number formatted is suitable for compacting in that locale, the compact version should instead be returned.The text was updated successfully, but these errors were encountered: