summaryrefslogtreecommitdiff
path: root/cell_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'cell_test.go')
-rw-r--r--cell_test.go32
1 files changed, 32 insertions, 0 deletions
diff --git a/cell_test.go b/cell_test.go
index d388c7f..ba326d9 100644
--- a/cell_test.go
+++ b/cell_test.go
@@ -1,6 +1,7 @@
package excelize
import (
+ "fmt"
"testing"
"github.com/stretchr/testify/assert"
@@ -39,3 +40,34 @@ func TestCheckCellInArea(t *testing.T) {
checkCellInArea("AA0", "Z0:AB1")
})
}
+
+func TestSetCellFloat(t *testing.T) {
+ sheet := "Sheet1"
+ t.Run("with no decimal", func(t *testing.T) {
+ f := NewFile()
+ f.SetCellFloat(sheet, "A1", 123.0, -1, 64)
+ f.SetCellFloat(sheet, "A2", 123.0, 1, 64)
+ assert.Equal(t, "123", f.GetCellValue(sheet, "A1"), "A1 should be 123")
+ assert.Equal(t, "123.0", f.GetCellValue(sheet, "A2"), "A2 should be 123.0")
+ })
+
+ t.Run("with a decimal and precision limit", func(t *testing.T) {
+ f := NewFile()
+ f.SetCellFloat(sheet, "A1", 123.42, 1, 64)
+ assert.Equal(t, "123.4", f.GetCellValue(sheet, "A1"), "A1 should be 123.4")
+ })
+
+ t.Run("with a decimal and no limit", func(t *testing.T) {
+ f := NewFile()
+ f.SetCellFloat(sheet, "A1", 123.42, -1, 64)
+ assert.Equal(t, "123.42", f.GetCellValue(sheet, "A1"), "A1 should be 123.42")
+ })
+}
+
+func ExampleFile_SetCellFloat() {
+ f := NewFile()
+ var x float64 = 3.14159265
+ f.SetCellFloat("Sheet1", "A1", x, 2, 64)
+ fmt.Println(f.GetCellValue("Sheet1", "A1"))
+ // Output: 3.14
+}