Skip to content

Commit

Permalink
Merge pull request #2 from jbzorg/float_culture
Browse files Browse the repository at this point in the history
Parse float as InvariantCulture
  • Loading branch information
NicholasNoise authored Oct 18, 2019
2 parents 4402a8c + b18a1b9 commit 2e45997
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions dBASE.NET/Encoders/FloatEncoder.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
namespace dBASE.NET.Encoders
{
using System;
using System.Globalization;
using System.Text;

internal class FloatEncoder : IEncoder
Expand All @@ -14,17 +15,25 @@ private FloatEncoder() { }
/// <inheritdoc />
public byte[] Encode(DbfField field, object data, Encoding encoding)
{
string text = Convert.ToString(data).PadLeft(field.Length, ' ');
if (text.Length > field.Length) text.Substring(0, field.Length);
string text = Convert.ToString(data, CultureInfo.InvariantCulture).PadLeft(field.Length, ' ');
if (text.Length > field.Length)
{
text.Substring(0, field.Length);
}

return encoding.GetBytes(text);
}

/// <inheritdoc />
public object Decode(byte[] buffer, byte[] memoData, Encoding encoding)
{
string text = encoding.GetString(buffer).Trim();
if (text.Length == 0) return null;
return Convert.ToSingle(text);
if (text.Length == 0)
{
return null;
}

return Convert.ToSingle(text, CultureInfo.InvariantCulture);
}
}
}

0 comments on commit 2e45997

Please sign in to comment.