MCPcopy
hub / github.com/spf13/cast / trimZeroDecimal

Function trimZeroDecimal

number.go:507–522  ·  view source on GitHub ↗
(s string)

Source from the content-addressed store, hash-verified

505}
506
507func trimZeroDecimal(s string) string {
508 var foundZero bool
509 for i := len(s); i > 0; i-- {
510 switch s[i-1] {
511 case '.':
512 if foundZero {
513 return s[:i-1]
514 }
515 case '0':
516 foundZero = true
517 default:
518 return s
519 }
520 }
521 return s
522}
523
524var stringNumberRe = regexp.MustCompile(`^([-+]?\d*)(\.\d*)?$`)
525

Callers 3

BenchmarkTrimZeroDecimalFunction · 0.85
TestTrimZeroDecimalFunction · 0.85
ToTimeInDefaultLocationEFunction · 0.85

Calls

no outgoing calls

Tested by 2

BenchmarkTrimZeroDecimalFunction · 0.68
TestTrimZeroDecimalFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…