decimal icon indicating copy to clipboard operation
decimal copied to clipboard

String with thousands separator

Open mamapi opened this issue 3 years ago • 1 comments

How to get string with thousands separator? e.g 4,294,967.45 for 4294967.45

mamapi avatar Dec 06 '21 10:12 mamapi

Hi again!

  • If you meant decimal string representation, currently it is not possible as decimal.String() is not parametrized. You would have to implement it by yourself.
  • If you meant parsing string representation of decimal with thousands separator there is a init method called decimal.NewFromFormattedString. It can be used for parsing differently formatted inputs using regular expressions.

Example:

r2 := regexp.MustCompile("[_]")
d2, err := NewFromFormattedString("1_000_000", r2)

mwoss avatar Dec 07 '21 23:12 mwoss