diff options
author | joeybloggs <Dean.Karn@gmail.com> | 2016-08-16 04:18:40 +0300 |
---|---|---|
committer | joeybloggs <Dean.Karn@gmail.com> | 2016-08-16 04:18:40 +0300 |
commit | 5e30685010ab9c6da8cc729a3e7eab0b1ae964ae (patch) | |
tree | 11782ebd7840c5c9bd60cdf318cd98898fb11fc7 /cmd | |
parent | 7a50918c70b219070868048aa533f5b142880103 (diff) |
add regular currency logic
Diffstat (limited to 'cmd')
-rw-r--r-- | cmd/currency.tmpl | 4 | ||||
-rw-r--r-- | cmd/generate_resources.go | 318 | ||||
-rw-r--r-- | cmd/translator.tmpl | 195 |
3 files changed, 395 insertions, 122 deletions
diff --git a/cmd/currency.tmpl b/cmd/currency.tmpl index af51167f..80c83eee 100644 --- a/cmd/currency.tmpl +++ b/cmd/currency.tmpl @@ -1,8 +1,8 @@ {{ define "currencies" }} package currency -// Currency is the type associated with the locales currency enum -type Currency int +// Type is the currency type associated with the locales currency enum +type Type int // locale currencies const ( diff --git a/cmd/generate_resources.go b/cmd/generate_resources.go index 38d732e3..1e028a2a 100644 --- a/cmd/generate_resources.go +++ b/cmd/generate_resources.go @@ -85,9 +85,25 @@ type translator struct { FmtPercentInPrefix bool FmtPercentLeft bool + // FmtCurrency vars + FmtCurrencyExists bool + FmtCurrencyGroupLen int + FmtCurrencySecondaryGroupLen int + FmtCurrencyMinDecimalLen int + FmtCurrencyPrefix string + FmtCurrencySuffix string + FmtCurrencyInPrefix bool + FmtCurrencyLeft bool + FmtCurrencyNegativePrefix string + FmtCurrencyNegativeSuffix string + FmtCurrencyNegativeInPrefix bool + FmtCurrencyNegativeLeft bool + // calculation only fields - DecimalNumberFormat string - PercentNumberFormat string + DecimalNumberFormat string + PercentNumberFormat string + CurrencyNumberFormat string + NegativeCurrencyNumberFormat string } func main() { @@ -116,7 +132,7 @@ func main() { for i, curr := range globalCurrencies { if i == 0 { - currencies = curr + " Currency = iota\n" + currencies = curr + " Type = iota\n" continue } @@ -149,7 +165,12 @@ func main() { for _, trans := range translators { - fmt.Println("Writing Data:", trans.PercentNumberFormat, len(trans.FmtPercentPrefix), trans.FmtPercentPrefix, len(trans.FmtPercentSuffix), trans.FmtPercentSuffix, trans.Locale) + fmt.Println("Writing Data:", trans.Locale) + + if trans.Locale == "en" { + fmt.Println("\t", trans.CurrencyNumberFormat) + fmt.Println("\t", trans.NegativeCurrencyNumberFormat) + } if err = os.MkdirAll(fmt.Sprintf(locDir, trans.Locale), 0777); err != nil { log.Fatal(err) @@ -289,6 +310,20 @@ func postProcess(cldr *cldr.CLDR) { } } + if len(trans.CurrencyNumberFormat) == 0 { + + if found { + trans.CurrencyNumberFormat = base.CurrencyNumberFormat + } + } + + if len(trans.NegativeCurrencyNumberFormat) == 0 { + + if found { + trans.NegativeCurrencyNumberFormat = base.NegativeCurrencyNumberFormat + } + } + ldml := cldr.RawLDML(trans.Locale) currencies := make([][]byte, len(globalCurrencies), len(globalCurrencies)) @@ -324,6 +359,7 @@ func postProcess(cldr *cldr.CLDR) { parseDecimalNumberFormat(trans) parsePercentNumberFormat(trans) + parseCurrencyNumberFormat(trans) // trans.FmtNumberFunc = parseDecimalNumberFormat(trans.DecimalNumberFormat, trans.BaseLocale) } } @@ -421,30 +457,24 @@ func preProcess(cldr *cldr.CLDR) { } } - // var decimalFormat, currencyFormat, currencyAccountingFormat, percentageFormat string - - // if len(ldml.Numbers.DecimalFormats) > 0 && len(ldml.Numbers.DecimalFormats[0].DecimalFormatLength) > 0 { - // decimalFormat = ldml.Numbers.DecimalFormats[0].DecimalFormatLength[0].DecimalFormat[0].Pattern[0].Data() - // } + if len(ldml.Numbers.CurrencyFormats) > 0 && len(ldml.Numbers.CurrencyFormats[0].CurrencyFormatLength) > 0 { - // if len(ldml.Numbers.CurrencyFormats) > 0 && len(ldml.Numbers.CurrencyFormats[0].CurrencyFormatLength) > 0 { + if len(ldml.Numbers.CurrencyFormats[0].CurrencyFormatLength[0].CurrencyFormat) > 1 { - // currencyFormat = ldml.Numbers.CurrencyFormats[0].CurrencyFormatLength[0].CurrencyFormat[0].Pattern[0].Data() - // currencyAccountingFormat = currencyFormat + split := strings.SplitN(ldml.Numbers.CurrencyFormats[0].CurrencyFormatLength[0].CurrencyFormat[1].Pattern[0].Data(), ";", 2) - // if len(ldml.Numbers.CurrencyFormats[0].CurrencyFormatLength[0].CurrencyFormat) > 1 { - // currencyAccountingFormat = ldml.Numbers.CurrencyFormats[0].CurrencyFormatLength[0].CurrencyFormat[1].Pattern[0].Data() - // } - // } + trans.CurrencyNumberFormat = split[0] - // if len(ldml.Numbers.PercentFormats) > 0 && len(ldml.Numbers.PercentFormats[0].PercentFormatLength) > 0 { - // percentageFormat = ldml.Numbers.PercentFormats[0].PercentFormatLength[0].PercentFormat[0].Pattern[0].Data() - // } - - // // parse Number values - // parseNumbers(decimal, group, minus, percent, permille, decimalFormat, currencyFormat, currencyAccountingFormat, percentageFormat) - - // end number values + if len(split) > 1 && len(split[1]) > 0 { + trans.NegativeCurrencyNumberFormat = split[1] + } else { + trans.NegativeCurrencyNumberFormat = trans.CurrencyNumberFormat + } + } else { + trans.CurrencyNumberFormat = ldml.Numbers.CurrencyFormats[0].CurrencyFormatLength[0].CurrencyFormat[0].Pattern[0].Data() + trans.NegativeCurrencyNumberFormat = trans.CurrencyNumberFormat + } + } } } @@ -459,20 +489,169 @@ func preProcess(cldr *cldr.CLDR) { } } -func parsePercentNumberFormat(trans *translator) (results string) { +func parseCurrencyNumberFormat(trans *translator) { - if len(trans.PercentNumberFormat) == 0 { + if len(trans.CurrencyNumberFormat) == 0 { return } - trans.FmtPercentExists = true + trans.FmtCurrencyExists = true + negativeEqual := trans.CurrencyNumberFormat == trans.NegativeCurrencyNumberFormat + + match := groupLenRegex.FindString(trans.CurrencyNumberFormat) + if len(match) > 0 { + trans.FmtCurrencyGroupLen = len(match) - 2 + } + + match = requiredDecimalRegex.FindString(trans.CurrencyNumberFormat) + if len(match) > 0 { + trans.FmtCurrencyMinDecimalLen = len(match) - 1 + } - // formats := strings.SplitN(trans.PercentNumberFormat, ";", 2) + match = secondaryGroupLenRegex.FindString(trans.CurrencyNumberFormat) + if len(match) > 0 { + trans.FmtCurrencySecondaryGroupLen = len(match) - 2 + } + + idx := 0 + + for idx = 0; idx < len(trans.CurrencyNumberFormat); idx++ { + if trans.CurrencyNumberFormat[idx] == '#' || trans.CurrencyNumberFormat[idx] == '0' { + trans.FmtCurrencyPrefix = trans.CurrencyNumberFormat[:idx] + break + } + } - // if len(formats) > 1 { - // trans.FmtNumberHasNegativeFormat = true + for idx = len(trans.CurrencyNumberFormat) - 1; idx >= 0; idx-- { + if trans.CurrencyNumberFormat[idx] == '#' || trans.CurrencyNumberFormat[idx] == '0' { + idx++ + trans.FmtCurrencySuffix = trans.CurrencyNumberFormat[idx:] + break + } + } + + for idx = 0; idx < len(trans.FmtCurrencyPrefix); idx++ { + if trans.FmtCurrencyPrefix[idx] == '¤' { + + trans.FmtCurrencyInPrefix = true + trans.FmtCurrencyPrefix = strings.Replace(trans.FmtCurrencyPrefix, string(trans.FmtCurrencyPrefix[idx]), "", 1) + + if idx == 0 { + trans.FmtCurrencyLeft = true + } else { + trans.FmtCurrencyLeft = false + } + + break + } + } + + for idx = 0; idx < len(trans.FmtCurrencySuffix); idx++ { + if trans.FmtCurrencySuffix[idx] == '¤' { + + trans.FmtCurrencyInPrefix = false + trans.FmtCurrencySuffix = strings.Replace(trans.FmtCurrencySuffix, string(trans.FmtCurrencySuffix[idx]), "", 1) + + if idx == 0 { + trans.FmtCurrencyLeft = true + } else { + trans.FmtCurrencyLeft = false + } + + break + } + } + + if len(trans.FmtCurrencyPrefix) > 0 { + trans.FmtCurrencyPrefix = fmt.Sprintf("%#v", []byte(trans.FmtCurrencyPrefix)) + } + + if len(trans.FmtCurrencySuffix) > 0 { + trans.FmtCurrencySuffix = fmt.Sprintf("%#v", []byte(trans.FmtCurrencySuffix)) + } + + // if trans.Locale == "en" { + // fmt.Println("Equal? ", negativeEqual) // } + // no need to parse again if true.... + if negativeEqual { + + trans.FmtCurrencyNegativePrefix = trans.FmtCurrencyPrefix + trans.FmtCurrencyNegativeSuffix = trans.FmtCurrencySuffix + trans.FmtCurrencyNegativeInPrefix = trans.FmtCurrencyInPrefix + trans.FmtCurrencyNegativeLeft = trans.FmtCurrencyLeft + + return + } + + for idx = 0; idx < len(trans.NegativeCurrencyNumberFormat); idx++ { + if trans.NegativeCurrencyNumberFormat[idx] == '#' || trans.NegativeCurrencyNumberFormat[idx] == '0' { + + trans.FmtCurrencyNegativePrefix = trans.NegativeCurrencyNumberFormat[:idx] + break + } + } + + for idx = len(trans.NegativeCurrencyNumberFormat) - 1; idx >= 0; idx-- { + if trans.NegativeCurrencyNumberFormat[idx] == '#' || trans.NegativeCurrencyNumberFormat[idx] == '0' { + idx++ + trans.FmtCurrencyNegativeSuffix = trans.NegativeCurrencyNumberFormat[idx:] + break + } + } + + for idx = 0; idx < len(trans.FmtCurrencyNegativePrefix); idx++ { + if trans.FmtCurrencyNegativePrefix[idx] == '¤' { + + trans.FmtCurrencyNegativeInPrefix = true + trans.FmtCurrencyNegativePrefix = strings.Replace(trans.FmtCurrencyNegativePrefix, string(trans.FmtCurrencyNegativePrefix[idx]), "", 1) + + if idx == 0 { + trans.FmtCurrencyNegativeLeft = true + } else { + trans.FmtCurrencyNegativeLeft = false + } + + break + } + } + + for idx = 0; idx < len(trans.FmtCurrencyNegativeSuffix); idx++ { + if trans.FmtCurrencyNegativeSuffix[idx] == '¤' { + + trans.FmtCurrencyNegativeInPrefix = false + trans.FmtCurrencyNegativeSuffix = strings.Replace(trans.FmtCurrencyNegativeSuffix, string(trans.FmtCurrencyNegativeSuffix[idx]), "", 1) + + if idx == 0 { + trans.FmtCurrencyNegativeLeft = true + } else { + trans.FmtCurrencyNegativeLeft = false + } + + break + } + } + + if len(trans.FmtCurrencyNegativePrefix) > 0 { + trans.FmtCurrencyNegativePrefix = fmt.Sprintf("%#v", []byte(trans.FmtCurrencyNegativePrefix)) + } + + if len(trans.FmtCurrencyNegativeSuffix) > 0 { + trans.FmtCurrencyNegativeSuffix = fmt.Sprintf("%#v", []byte(trans.FmtCurrencyNegativeSuffix)) + } + + return +} + +func parsePercentNumberFormat(trans *translator) { + + if len(trans.PercentNumberFormat) == 0 { + return + } + + trans.FmtPercentExists = true + match := groupLenPercentRegex.FindString(trans.PercentNumberFormat) if len(match) > 0 { trans.FmtPercentGroupLen = len(match) - 1 @@ -488,17 +667,6 @@ func parsePercentNumberFormat(trans *translator) (results string) { trans.FmtPercentSecondaryGroupLen = len(match) - 2 } - // FmtPercentPrefix string - // FmtPercentSuffix string - // FmtPercentInPrefix bool - // FmtPercentLeft bool - - // if formats[0][0] == '%' { - // trans.FmtPercentLeft = true - // } - - // trans.FmtPercentLeft - idx := 0 for idx = 0; idx < len(trans.PercentNumberFormat); idx++ { @@ -518,14 +686,14 @@ func parsePercentNumberFormat(trans *translator) (results string) { for idx = 0; idx < len(trans.FmtPercentPrefix); idx++ { if trans.FmtPercentPrefix[idx] == '%' { + trans.FmtPercentInPrefix = true + trans.FmtPercentPrefix = strings.Replace(trans.FmtPercentPrefix, string(trans.FmtPercentPrefix[idx]), "", 1) if idx == 0 { trans.FmtPercentLeft = true - trans.FmtPercentPrefix = trans.FmtPercentPrefix[idx+1:] } else { trans.FmtPercentLeft = false - trans.FmtPercentPrefix = trans.FmtPercentPrefix[:idx] } break @@ -534,14 +702,14 @@ func parsePercentNumberFormat(trans *translator) (results string) { for idx = 0; idx < len(trans.FmtPercentSuffix); idx++ { if trans.FmtPercentSuffix[idx] == '%' { + trans.FmtPercentInPrefix = false + trans.FmtPercentSuffix = strings.Replace(trans.FmtPercentSuffix, string(trans.FmtPercentSuffix[idx]), "", 1) if idx == 0 { trans.FmtPercentLeft = true - trans.FmtPercentSuffix = trans.FmtPercentSuffix[idx+1:] } else { trans.FmtPercentLeft = false - trans.FmtPercentSuffix = trans.FmtPercentSuffix[:idx] } break @@ -556,37 +724,10 @@ func parsePercentNumberFormat(trans *translator) (results string) { trans.FmtPercentSuffix = fmt.Sprintf("%#v", []byte(trans.FmtPercentSuffix)) } - // if len(trans.FmtPercentPrefix) == 1 && trans.FmtPercentPrefix[0] == '%' { - // trans.FmtPercentPrefix = "" - // trans.FmtPercentInPrefix = true - // } - - // if len(trans.FmtPercentSuffix) == 1 && trans.FmtPercentSuffix[0] == '%' { - // trans.FmtPercentSuffix = "" - // trans.FmtPercentSuffix = false - // } - - // // if start > 0 { - // // prefix = formats[0][:start] - // // } - - // end := 0 - - // // positive prefix - // for end = len(formats[0]) - 1; end >= 0; end-- { - // if formats[0][end] == '#' || formats[0][end] == '0' { - // end++ - // break - // } - // } - - // fmt.Println(start) - // fmt.Println(end) - return } -func parseDecimalNumberFormat(trans *translator) (results string) { +func parseDecimalNumberFormat(trans *translator) { if len(trans.DecimalNumberFormat) == 0 { return @@ -596,10 +737,6 @@ func parseDecimalNumberFormat(trans *translator) (results string) { formats := strings.SplitN(trans.DecimalNumberFormat, ";", 2) - // if len(formats) > 1 { - // trans.FmtNumberHasNegativeFormat = true - // } - match := groupLenRegex.FindString(formats[0]) if len(match) > 0 { trans.FmtNumberGroupLen = len(match) - 2 @@ -615,33 +752,6 @@ func parseDecimalNumberFormat(trans *translator) (results string) { trans.FmtNumberSecondaryGroupLen = len(match) - 2 } - // start := 0 - // // prefix := "" - - // // positive prefix - // for start = 0; start < len(formats[0]); start++ { - // if formats[0][start] == '#' || formats[0][start] == '0' { - // break - // } - // } - - // // if start > 0 { - // // prefix = formats[0][:start] - // // } - - // end := 0 - - // // positive prefix - // for end = len(formats[0]) - 1; end >= 0; end-- { - // if formats[0][end] == '#' || formats[0][end] == '0' { - // end++ - // break - // } - // } - - // fmt.Println(start) - // fmt.Println(end) - return } diff --git a/cmd/translator.tmpl b/cmd/translator.tmpl index 577ab046..f66a3ef4 100644 --- a/cmd/translator.tmpl +++ b/cmd/translator.tmpl @@ -5,20 +5,25 @@ import ( "math" "github.com/go-playground/locales" + "github.com/go-playground/locales/currency" ) type {{ .Locale }} struct { - locale string - pluralsCardinal []locales.PluralRule - pluralsOrdinal []locales.PluralRule - decimal []byte - group []byte - minus []byte - percent []byte - percentPrefix []byte - percentSuffix []byte - perMille []byte - currencies [][]byte // idx = enum of currency code + locale string + pluralsCardinal []locales.PluralRule + pluralsOrdinal []locales.PluralRule + decimal []byte + group []byte + minus []byte + percent []byte + percentPrefix []byte + percentSuffix []byte + perMille []byte + currencies [][]byte // idx = enum of currency code + currencyPositivePrefix []byte + currencyPositiveSuffix []byte + currencyNegativePrefix []byte + currencyNegativeSuffix []byte } // New returns a new instance of translator for the '{{ .Locale }}' locale @@ -33,12 +38,24 @@ func New() locales.Translator { percent: {{ .Percent }}, perMille: {{ .PerMille }}, currencies: {{ .Currencies }}, - {{ if gt (len .FmtPercentPrefix) 0}} + {{- if gt (len .FmtPercentPrefix) 0}} percentPrefix: {{ .FmtPercentPrefix }}, {{ end -}} - {{ if gt (len .FmtPercentSuffix) 0}} + {{- if gt (len .FmtPercentSuffix) 0}} percentSuffix: {{ .FmtPercentSuffix }}, {{ end -}} + {{- if gt (len .FmtCurrencyPrefix) 0}} + currencyPositivePrefix: {{ .FmtCurrencyPrefix }}, + {{ end -}} + {{- if gt (len .FmtCurrencySuffix) 0}} + currencyPositiveSuffix: {{ .FmtCurrencySuffix }}, + {{ end -}} + {{- if gt (len .FmtCurrencyNegativePrefix) 0}} + currencyNegativePrefix: {{ .FmtCurrencyNegativePrefix }}, + {{ end -}} + {{- if gt (len .FmtCurrencyNegativeSuffix) 0}} + currencyNegativeSuffix: {{ .FmtCurrencyNegativeSuffix }}, + {{ end -}} } } @@ -306,6 +323,19 @@ func({{ .BaseLocale }} *{{ .Locale }}) FmtPercent(num float64, v uint64) []byte b[i], b[j] = b[j], b[i] } + {{ if gt .FmtPercentMinDecimalLen 0 }} + if int(v) < {{ .FmtPercentMinDecimalLen }} { + + if v == 0 { + b = append(b, {{ .BaseLocale }}.decimal...) + } + + for i := 0; i < {{ .FmtPercentMinDecimalLen }}-int(v); i++ { + b = append(b, '0') + } + } + {{ end }} + {{ if and (not .FmtPercentInPrefix) .FmtPercentLeft }} b = append(b, {{ .BaseLocale }}.percent...) {{ end }} @@ -318,19 +348,152 @@ func({{ .BaseLocale }} *{{ .Locale }}) FmtPercent(num float64, v uint64) []byte b = append(b, {{ .BaseLocale }}.percent...) {{ end }} - {{ if gt .FmtPercentMinDecimalLen 0 }} - if int(v) < {{ .FmtPercentMinDecimalLen }} { + return b + {{ else }} + return []byte(s) + {{ end -}} +} + +// FmtCurrency returns the currency representation of 'num' with digits/precision of 'v' for '{{ .Locale }}' +// returned as a []byte just in case the caller wishes to add more and can help +// avoid allocations; otherwise just cast as string. +func({{ .BaseLocale }} *{{ .Locale }}) FmtCurrency(num float64, v uint64, currency currency.Type) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + symbol := {{ .BaseLocale }}.currencies[currency] + {{- if eq .FmtCurrencyExists true }} + {{- if gt .FmtCurrencyGroupLen 0 }} + l := len(s) + len({{ .BaseLocale }}.decimal) + len({{ .BaseLocale }}.group) * len(s[:len(s)-int(v)-1]) / {{ .FmtCurrencyGroupLen }} + count := 0 + inWhole := v == 0 + {{- if gt .FmtCurrencySecondaryGroupLen 0}} + inSecondary := false + groupThreshold := {{ .FmtCurrencyGroupLen }} + {{ end -}} + {{ else }} + l := len(s) + len({{ .BaseLocale }}.decimal) + {{ end }} + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + + {{- if eq .DecimalLen 1 }} + b = append(b, {{ .BaseLocale }}.decimal[0]) + {{- else }} + for j := len({{ .BaseLocale }}.decimal) - 1; j >= 0; j-- { + b = append(b, {{ .BaseLocale }}.decimal[j]) + } + {{ end -}} + {{- if gt .FmtCurrencyGroupLen 0 }} + inWhole = true + {{ end }} + continue + } + + {{ if gt .FmtCurrencyGroupLen 0 }} + if inWhole { + + {{- if gt .FmtCurrencySecondaryGroupLen 0}} + + if count == groupThreshold { + {{- if eq .GroupLen 1 }} + b = append(b, {{ .BaseLocale }}.group[0]) + {{- else }} + for j := len({{ .BaseLocale }}.group) - 1; j >= 0; j-- { + b = append(b, {{ .BaseLocale }}.group[j]) + } + {{ end }} + count = 1 + + if !inSecondary { + inSecondary = true + groupThreshold = {{ .FmtCurrencySecondaryGroupLen }} + } + {{ else }} + if count == {{ .FmtCurrencyGroupLen }} { + {{- if eq .GroupLen 1 }} + b = append(b, {{ .BaseLocale }}.group[0]) + {{- else }} + for j := len({{ .BaseLocale }}.group) - 1; j >= 0; j-- { + b = append(b, {{ .BaseLocale }}.group[j]) + } + {{ end }} + count = 1 + {{ end -}} + } else { + count++ + } + } + + {{ end }} + + b = append(b, s[i]) + } + + {{ if and .FmtCurrencyInPrefix (not .FmtCurrencyLeft) }} + for j := len(symbol) - 1; j >= 0; j-- { + b = append(b, symbol[j]) + } + {{ end }} + + {{ if gt (len .FmtCurrencyPrefix) 0}} + {{- if eq (len .FmtCurrencyPrefix) 1 }} + b = append(b, {{ .BaseLocale }}.currencyPositivePrefix[0]) + {{ else }} + for j := len({{ .BaseLocale }}.currencyPositivePrefix) - 1; j >= 0; j-- { + b = append(b, {{ .BaseLocale }}.currencyPositivePrefix[j]) + } + {{ end }} + {{ end }} + + {{ if and .FmtCurrencyInPrefix .FmtCurrencyLeft }} + for j := len(symbol) - 1; j >= 0; j-- { + b = append(b, symbol[j]) + } + {{ end }} + + if num < 0 { + {{- if eq .MinusLen 1 }} + b = append(b, {{ .BaseLocale }}.minus[0]) + {{ else }} + for j := len({{ .BaseLocale }}.minus) - 1; j >= 0; j-- { + b = append(b, {{ .BaseLocale }}.minus[j]) + } + {{ end -}} + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + {{ if gt .FmtCurrencyMinDecimalLen 0 }} + if int(v) < {{ .FmtCurrencyMinDecimalLen }} { if v == 0 { b = append(b, {{ .BaseLocale }}.decimal...) } - for i := 0; i < {{ .FmtPercentMinDecimalLen }}-int(v); i++ { + for i := 0; i < {{ .FmtCurrencyMinDecimalLen }}-int(v); i++ { b = append(b, '0') } } {{ end }} + {{ if and (not .FmtCurrencyInPrefix) .FmtCurrencyLeft }} + b = append(b, symbol...) + {{ end }} + + {{ if gt (len .FmtCurrencySuffix) 0}} + b = append(b, {{ .BaseLocale }}.currencyPositiveSuffix...) + {{ end }} + + {{ if and (not .FmtCurrencyInPrefix) (not .FmtCurrencyLeft) }} + b = append(b, symbol...) + {{ end }} + return b {{ else }} return []byte(s) |