-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(rounding): check if the value is a float
check the value is a float and if it is, convert it to a float then convert back to a string by rounding off the significant zeros to the expected amount. +ref: #55
- Loading branch information
1 parent
63eb307
commit 567249e
Showing
4 changed files
with
54 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package xlsxreader | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func getColCount(f *XlsxFileCloser) int { | ||
row := <-f.ReadRows(f.Sheets[0]) | ||
if row.Error != nil { | ||
return 0 | ||
} | ||
return asIndex(row.Cells[len(row.Cells)-1].Column) + 1 | ||
} | ||
|
||
func TestFloatingPointRounding(t *testing.T) { | ||
|
||
t.Run("rounding", func(t *testing.T) { | ||
xl, err := OpenFile("./test/test-rounding.xlsx") | ||
// Create an instance of the reader by opening a target file | ||
var target string | ||
// Ensure the file reader is closed once utilised | ||
defer xl.Close() | ||
numColumns := getColCount(xl) | ||
for row := range xl.ReadRows(xl.Sheets[0]) { | ||
if row.Error != nil { | ||
continue | ||
} | ||
csvRow := make([]string, numColumns) | ||
for _, curCell := range row.Cells { | ||
colIndex := asIndex(curCell.Column) | ||
if curCell.Column == "L" && curCell.Row == 2 { | ||
target = curCell.Value | ||
} | ||
if colIndex < numColumns { | ||
csvRow[colIndex] = curCell.Value | ||
} | ||
} | ||
|
||
} | ||
|
||
require.NoError(t, err) | ||
require.Equal(t, "4.4", target) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.