MCPcopy
hub / github.com/shopspring/decimal / NewFromFormattedString

Function NewFromFormattedString

decimal.go:265–272  ·  view source on GitHub ↗

NewFromFormattedString returns a new Decimal from a formatted string representation. The second argument - replRegexp, is a regular expression that is used to find characters that should be removed from given decimal string representation. All matched characters will be replaced with an empty string

(value string, replRegexp *regexp.Regexp)

Source from the content-addressed store, hash-verified

263// r3 := regexp.MustCompile("[USD\\s]")
264// d3, err := NewFromFormattedString("5000 USD", r3)
265func NewFromFormattedString(value string, replRegexp *regexp.Regexp) (Decimal, error) {
266 parsedValue := replRegexp.ReplaceAllString(value, "")
267 d, err := NewFromString(parsedValue)
268 if err != nil {
269 return Decimal{}, err
270 }
271 return d, nil
272}
273
274// RequireFromString returns a new Decimal from a string representation
275// or panics if NewFromString had returned an error.

Callers 1

Calls 1

NewFromStringFunction · 0.85

Tested by 1

Used in the wild real call sites across dependent graphs

searching dependent graphs…