mirror of
https://github.com/ManyakRus/starter.git
synced 2025-11-23 22:45:11 +02:00
сделал humanize
This commit is contained in:
48
humanize/humanize.go
Normal file
48
humanize/humanize.go
Normal file
@@ -0,0 +1,48 @@
|
||||
package humanize
|
||||
|
||||
import "github.com/dustin/go-humanize"
|
||||
|
||||
// StringFromFloat64_underline - преобразование float64 в строку, с разделителями тысяч
|
||||
func StringFromFloat64_underline(f float64) string {
|
||||
Otvet := ""
|
||||
|
||||
Otvet = humanize.FormatFloat("#_###.##", f)
|
||||
|
||||
return Otvet
|
||||
}
|
||||
|
||||
// StringFromFloat32_underline - преобразование float64 в строку, с разделителями тысяч
|
||||
func StringFromFloat32_underline(f float32) string {
|
||||
Otvet := ""
|
||||
|
||||
Otvet = humanize.FormatFloat("#_###.##", float64(f))
|
||||
|
||||
return Otvet
|
||||
}
|
||||
|
||||
// StringFromInt_underline - преобразование int в строку, с разделителями тысяч
|
||||
func StringFromInt_underline(i int) string {
|
||||
Otvet := ""
|
||||
|
||||
Otvet = humanize.FormatInteger("#_###.", i)
|
||||
|
||||
return Otvet
|
||||
}
|
||||
|
||||
// StringFromInt32_underline - преобразование int32 в строку, с разделителями тысяч
|
||||
func StringFromInt32_underline(i int32) string {
|
||||
Otvet := ""
|
||||
|
||||
Otvet = humanize.FormatInteger("#_###.", int(i))
|
||||
|
||||
return Otvet
|
||||
}
|
||||
|
||||
// StringFromInt64_underline - преобразование int64 в строку, с разделителями тысяч
|
||||
func StringFromInt64_underline(i int64) string {
|
||||
Otvet := ""
|
||||
|
||||
Otvet = humanize.FormatInteger("#_###.", int(i))
|
||||
|
||||
return Otvet
|
||||
}
|
||||
40
humanize/humanize_test.go
Normal file
40
humanize/humanize_test.go
Normal file
@@ -0,0 +1,40 @@
|
||||
package humanize
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestStringFromFloat64_underline(t *testing.T) {
|
||||
|
||||
Otvet := StringFromFloat64_underline(1123.456)
|
||||
if Otvet != "1_123.46" {
|
||||
t.Error("Error")
|
||||
}
|
||||
}
|
||||
|
||||
func TestStringFromFloat32_underline(t *testing.T) {
|
||||
|
||||
Otvet := StringFromFloat32_underline(1123.456)
|
||||
if Otvet != "1_123.46" {
|
||||
t.Error("Error")
|
||||
}
|
||||
}
|
||||
|
||||
func TestStringFromInt_underline(t *testing.T) {
|
||||
Otvet := StringFromInt_underline(1123)
|
||||
if Otvet != "1_123" {
|
||||
t.Error("Error")
|
||||
}
|
||||
}
|
||||
|
||||
func TestStringFromInt64_underline(t *testing.T) {
|
||||
Otvet := StringFromInt64_underline(1123)
|
||||
if Otvet != "1_123" {
|
||||
t.Error("Error")
|
||||
}
|
||||
}
|
||||
|
||||
func TestStringFromInt32_underline(t *testing.T) {
|
||||
Otvet := StringFromInt32_underline(1123)
|
||||
if Otvet != "1_123" {
|
||||
t.Error("Error")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user