From d2a28ae19f2ef9a7f55c6af65be835657eacda45 Mon Sep 17 00:00:00 2001 From: Steven te Brinke Date: Fri, 23 Oct 2015 16:31:36 +0200 Subject: [PATCH] Currency is stored as 64bit numbers. --- lib/dbf/column/base.rb | 2 +- spec/dbf/column_spec.rb | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/dbf/column/base.rb b/lib/dbf/column/base.rb index fad45a5f..1470f5ea 100644 --- a/lib/dbf/column/base.rb +++ b/lib/dbf/column/base.rb @@ -111,7 +111,7 @@ def unpack_number(value) # nodoc end def unpack_currency(value) # nodoc - (unpack_signed_long(value) / 10_000.0).to_f + (value.unpack('q<')[0] / 10_000.0).to_f end def unpack_signed_long(value) # nodoc diff --git a/spec/dbf/column_spec.rb b/spec/dbf/column_spec.rb index f700ebfa..ecb2274d 100644 --- a/spec/dbf/column_spec.rb +++ b/spec/dbf/column_spec.rb @@ -273,6 +273,11 @@ expect(column.type_cast("\xFC\xF0\xF0\xFE\xFF\xFF\xFF\xFF")).to eq -1776.41 end + it 'supports 64bit negative currency' do + expect(column.type_cast("pN'9\xFF\xFF\xFF\xFF")).to be_a(Float) + expect(column.type_cast("pN'9\xFF\xFF\xFF\xFF")).to eq -333609.0 + end + context 'and 0 length' do it 'returns nil' do column = DBF::Column::Dbase.new table, "ColumnName", "Y", 0, 0