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

Method string

decimal.go:1908–1951  ·  view source on GitHub ↗
(trimTrailingZeros bool)

Source from the content-addressed store, hash-verified

1906}
1907
1908func (d Decimal) string(trimTrailingZeros bool) string {
1909 if d.exp >= 0 {
1910 return d.rescale(0).value.String()
1911 }
1912
1913 abs := new(big.Int).Abs(d.value)
1914 str := abs.String()
1915
1916 var intPart, fractionalPart string
1917
1918 // NOTE(vadim): this cast to int will cause bugs if d.exp == INT_MIN
1919 // and you are on a 32-bit machine. Won't fix this super-edge case.
1920 dExpInt := int(d.exp)
1921 if len(str) > -dExpInt {
1922 intPart = str[:len(str)+dExpInt]
1923 fractionalPart = str[len(str)+dExpInt:]
1924 } else {
1925 intPart = "0"
1926
1927 num0s := -dExpInt - len(str)
1928 fractionalPart = strings.Repeat("0", num0s) + str
1929 }
1930
1931 if trimTrailingZeros {
1932 i := len(fractionalPart) - 1
1933 for ; i >= 0; i-- {
1934 if fractionalPart[i] != '0' {
1935 break
1936 }
1937 }
1938 fractionalPart = fractionalPart[:i+1]
1939 }
1940
1941 number := intPart
1942 if len(fractionalPart) > 0 {
1943 number += "." + fractionalPart
1944 }
1945
1946 if d.value.Sign() < 0 {
1947 return "-" + number
1948 }
1949
1950 return number
1951}
1952
1953func (d *Decimal) ensureInitialized() {
1954 if d.value == nil {

Callers 4

StringMethod · 0.95
StringFixedMethod · 0.80
StringFixedBankMethod · 0.80
StringFixedCashMethod · 0.80

Calls 4

rescaleMethod · 0.95
AbsMethod · 0.80
SignMethod · 0.80
StringMethod · 0.45

Tested by

no test coverage detected