mirror of
https://github.com/ManyakRus/starter.git
synced 2025-11-25 23:02:22 +02:00
сделал StringFromFloat64_Dimension0()
This commit is contained in:
@@ -950,20 +950,48 @@ func FindLastPos(s, TextFind string) int {
|
||||
return Otvet
|
||||
}
|
||||
|
||||
// StringFloat64_Dimension2 - возвращает строку с 2 знака после запятой
|
||||
func StringFloat64_Dimension2(f float64) string {
|
||||
// StringFromFloat64_Dimension2 - возвращает строку с 2 знака после запятой
|
||||
func StringFromFloat64_Dimension2(f float64) string {
|
||||
Otvet := fmt.Sprintf("%.2f", f)
|
||||
|
||||
return Otvet
|
||||
}
|
||||
|
||||
// StringFloat32_Dimension2 - возвращает строку с 2 знака после запятой
|
||||
func StringFloat32_Dimension2(f float32) string {
|
||||
// StringFromFloat32_Dimension2 - возвращает строку с 2 знака после запятой
|
||||
func StringFromFloat32_Dimension2(f float32) string {
|
||||
Otvet := fmt.Sprintf("%.2f", f)
|
||||
|
||||
return Otvet
|
||||
}
|
||||
|
||||
// StringFromFloat64_Dimension0 - возвращает строку с 0 знаков после запятой
|
||||
func StringFromFloat64_Dimension0(f float64) string {
|
||||
Otvet := fmt.Sprintf("%.0f", f)
|
||||
|
||||
return Otvet
|
||||
}
|
||||
|
||||
// StringFromFloat32_Dimension0 - возвращает строку с 0 знаков после запятой
|
||||
func StringFromFloat32_Dimension0(f float32) string {
|
||||
Otvet := fmt.Sprintf("%.0f", f)
|
||||
|
||||
return Otvet
|
||||
}
|
||||
|
||||
// StringFromFloat64_Dimension - возвращает строку с Dimension знаков после запятой
|
||||
func StringFromFloat64_Dimension(f float64, Dimension int) string {
|
||||
Otvet := fmt.Sprintf("%."+strconv.Itoa(Dimension)+"f", f)
|
||||
|
||||
return Otvet
|
||||
}
|
||||
|
||||
// StringFromFloat32_Dimension - возвращает строку с Dimension знаков после запятой
|
||||
func StringFromFloat32_Dimension(f float32, Dimension int) string {
|
||||
Otvet := fmt.Sprintf("%."+strconv.Itoa(Dimension)+"f", f)
|
||||
|
||||
return Otvet
|
||||
}
|
||||
|
||||
// ShowTimePassed - показывает время прошедшее с момента старта
|
||||
// запускать:
|
||||
// defer micro.ShowTimePassed(time.Now())
|
||||
|
||||
@@ -566,41 +566,41 @@ func TestFindLastPos(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestStringFloat64_Dimension2(t *testing.T) {
|
||||
func TestStringFromFloat64_Dimension2(t *testing.T) {
|
||||
// Testing for a positive float number
|
||||
result := StringFloat64_Dimension2(3.14159)
|
||||
result := StringFromFloat64_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)
|
||||
result = StringFromFloat64_Dimension2(-123.456)
|
||||
if result != "-123.46" {
|
||||
t.Errorf("Expected '-123.46' but got %s", result)
|
||||
}
|
||||
|
||||
// Testing for zero
|
||||
result = StringFloat64_Dimension2(0.0)
|
||||
result = StringFromFloat64_Dimension2(0.0)
|
||||
if result != "0.00" {
|
||||
t.Errorf("Expected '0.00' but got %s", result)
|
||||
}
|
||||
}
|
||||
|
||||
func TestStringFloat32_Dimension2(t *testing.T) {
|
||||
func TestStringFromFloat32_Dimension2(t *testing.T) {
|
||||
// Testing for a positive float number
|
||||
result := StringFloat32_Dimension2(3.14159)
|
||||
result := StringFromFloat32_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)
|
||||
result = StringFromFloat32_Dimension2(-123.456)
|
||||
if result != "-123.46" {
|
||||
t.Errorf("Expected '-123.46' but got %s", result)
|
||||
}
|
||||
|
||||
// Testing for zero
|
||||
result = StringFloat32_Dimension2(0.0)
|
||||
result = StringFromFloat32_Dimension2(0.0)
|
||||
if result != "0.00" {
|
||||
t.Errorf("Expected '0.00' but got %s", result)
|
||||
}
|
||||
@@ -1412,3 +1412,35 @@ func TestMinFloat64(t *testing.T) {
|
||||
t.Errorf("Expected 1.0, but got %f", Otvet)
|
||||
}
|
||||
}
|
||||
|
||||
func TestStringFromFloat64_Dimension0(t *testing.T) {
|
||||
var f float64 = 1.0
|
||||
Otvet := StringFromFloat64_Dimension0(f)
|
||||
if Otvet != "1" {
|
||||
t.Errorf("Expected '1', but got %s", Otvet)
|
||||
}
|
||||
}
|
||||
|
||||
func TestStringFromFloat32_Dimension0(t *testing.T) {
|
||||
var f float32 = 1.0
|
||||
Otvet := StringFromFloat32_Dimension0(f)
|
||||
if Otvet != "1" {
|
||||
t.Errorf("Expected '1', but got %s", Otvet)
|
||||
}
|
||||
}
|
||||
|
||||
func TestStringFromFloat64_Dimension(t *testing.T) {
|
||||
var f float64 = 1.0
|
||||
Otvet := StringFromFloat64_Dimension(f, 0)
|
||||
if Otvet != "1" {
|
||||
t.Errorf("Expected '1', but got %s", Otvet)
|
||||
}
|
||||
}
|
||||
|
||||
func TestStringFromFloat32_Dimension(t *testing.T) {
|
||||
var f float32 = 1.0
|
||||
Otvet := StringFromFloat32_Dimension(f, 0)
|
||||
if Otvet != "1" {
|
||||
t.Errorf("Expected '1', but got %s", Otvet)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user