Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added testdata/decimal.xls
Binary file not shown.
8 changes: 7 additions & 1 deletion xls/structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ type boundSheet struct {
Name string
}

///////
// /////
type shRow struct {
RowIndex uint16 // 0-based
FirstCol uint16 // 0-based
Expand Down Expand Up @@ -88,6 +88,12 @@ func (r RKNumber) Int() int {

func (r RKNumber) Float64() float64 {
val := int32(r) >> 2

// Value is saved as integer multiplied by 100
if (r&1) != 0 && (r&2) != 0 {
return float64(val) / 100.0
}

v2 := math.Float64frombits(uint64(val) << 34)

if (r&1) == 0 && (r&2) == 0 {
Expand Down
25 changes: 25 additions & 0 deletions xls/structs_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package xls

import (
"testing"

"github.com/pbnjay/grate"
)

func TestDecimalNumberSavedAsIntegerMultipliedByHundred(t *testing.T) {
wb, _ := grate.Open("../testdata/decimal.xls")
sheets, _ := wb.List()
for _, s := range sheets {
sheet, _ := wb.Get(s)
sheet.Next()

var value float64
sheet.Scan(&value)

if value != 1.75 {
t.Log("Expected value to be 1.75, but actually is", value)
t.Fail()
}
}
wb.Close()
}