1
0
mirror of https://github.com/ManyakRus/starter.git synced 2025-11-24 22:53:52 +02:00

сделал StringFloat64_Dimension2()

This commit is contained in:
Nikitin Aleksandr
2024-03-20 17:50:18 +03:00
parent 30d7c74284
commit 0159d248d7
2 changed files with 54 additions and 0 deletions

View File

@@ -808,3 +808,17 @@ func FindLastPos(s, TextFind string) int {
Otvet := strings.LastIndex(s, TextFind)
return Otvet
}
// StringFloat64_Dimension2 - возвращает строку с 2 знака после запятой
func StringFloat64_Dimension2(f float64) string {
Otvet := fmt.Sprintf("%.2f", f)
return Otvet
}
// StringFloat32_Dimension2 - возвращает строку с 2 знака после запятой
func StringFloat32_Dimension2(f float32) string {
Otvet := fmt.Sprintf("%.2f", f)
return Otvet
}

View File

@@ -554,3 +554,43 @@ func TestFindLastPos(t *testing.T) {
t.Error("microfunctions_test.TestFindLastPos() FindLastPos()=nil !")
}
}
func TestStringFloat64_Dimension2(t *testing.T) {
// Testing for a positive float number
result := StringFloat64_Dimension2(3.14159)
if result != "3.14" {
t.Errorf("Expected '3.14' but got %s", result)
}
// Testing for a negative float number
result = StringFloat64_Dimension2(-123.456)
if result != "-123.46" {
t.Errorf("Expected '-123.46' but got %s", result)
}
// Testing for zero
result = StringFloat64_Dimension2(0.0)
if result != "0.00" {
t.Errorf("Expected '0.00' but got %s", result)
}
}
func TestStringFloat32_Dimension2(t *testing.T) {
// Testing for a positive float number
result := StringFloat32_Dimension2(3.14159)
if result != "3.14" {
t.Errorf("Expected '3.14' but got %s", result)
}
// Testing for a negative float number
result = StringFloat32_Dimension2(-123.456)
if result != "-123.46" {
t.Errorf("Expected '-123.46' but got %s", result)
}
// Testing for zero
result = StringFloat32_Dimension2(0.0)
if result != "0.00" {
t.Errorf("Expected '0.00' but got %s", result)
}
}