From b5f5b2cba99ab2dd66177ff3cdabc0714702919c Mon Sep 17 00:00:00 2001 From: Rafael Pinheiro Date: Fri, 13 Aug 2021 15:38:44 -0300 Subject: [PATCH 1/2] correct mask datetime LAYOUT_YYYY_MM_DDTHH_MM_SS_000 --- datetime.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/datetime.go b/datetime.go index 8c8e369..ac20acd 100644 --- a/datetime.go +++ b/datetime.go @@ -20,7 +20,7 @@ const LAYOUT_HHMMSS = "150405" const LAYOUT_HH = "15" const LAYOUT_HH_MM_SS = "15:04:05" const LAYOUT_YYYY_MM_DDTHH_MM_SS_000Z = "2006-01-02T15:04:05.000Z" -const LAYOUT_YYYY_MM_DDTHH_MM_SS_000 = "2006-01-02 15:04:05" +const LAYOUT_YYYY_MM_DDTHH_MM_SS_000 = "2006-01-02T15:04:05.000" /* ConvertStringToTimeLayoutDDMMYYYY @@ -143,6 +143,13 @@ func ConvertStringToTimeLayoutYYYY_MM_DDTHH_MM_SS_000(value string) time.Time { return t } +/* + ConvertTimeToStringLayoutYYYY_MM_DDTHH_MM_SS_000 +*/ +func ConvertTimeToStringLayoutYYYY_MM_DDTHH_MM_SS_000(date time.Time) string { + return date.Format(LAYOUT_YYYY_MM_DDTHH_MM_SS_000) +} + /* ConvertStringToTimeLayoutHHMMSS */ From 327b91fac67edb0fa94ce34f7be1f849451161d3 Mon Sep 17 00:00:00 2001 From: Vicente Date: Thu, 19 Aug 2021 08:08:44 -0300 Subject: [PATCH 2/2] add ConvertFloatToBrMoneyString --- README.md | 3 ++- float.go | 31 ++++++++++++++++++++++++++++++- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 8718ea4..46677e6 100644 --- a/README.md +++ b/README.md @@ -99,7 +99,8 @@ ConvertFloat64ToString4Decimal(value string) Return float64 ConvertStringToFloat64(value string) Return float64 ConvertStringToFloatScale2Comma(value string) Return float64 ConvertStringToFloatScale2FormatNumber(value string) Return float64 -ConvertStringToFloatScale2(value string) float64 +ConvertStringToFloatScale2(value string) Return float64 +ConvertFloatToBrMoneyString(value float64) Return string ``` ### ftp.go diff --git a/float.go b/float.go index d2ad32d..815eef2 100644 --- a/float.go +++ b/float.go @@ -89,4 +89,33 @@ func ConvertStringToFloatScale2(value string) float64 { } s, _ := strconv.ParseFloat(value, 64) return s -} \ No newline at end of file +} + +/* + ConvertFloatToBrMoneyString +*/ +func ConvertFloatToBrMoneyString(value float64) string{ + str := fmt.Sprintf("%.2f", value) + split := strings.Split(str, ".") + + number := split[0] + decimal := "00" + if len(split) > 0 { + decimal = split[1] + } + + var values []string + + if len(number) < 3 { + values = append(values, number) + } else { + for i := len(number); i > 0; i -= 3 { + j := i-3 + if j < 0 { + j = 0 + } + values = append([]string{number[j:i]}, values...) + } + } + return strings.Join(values[:], ".") + `,` + decimal +}