0

I'm getting records from a MS Access database. The database decimal separator is comma and I can't change it. The value from the SQL result casted into Double return wrong value as it's not the same in the database, I guess because of different Cultures in the database and the code. I'm using Petapoco library.

There is probably a way to set the Culture into Petapoco but how ?

public class TExternalProp
{
    public String ObjectID { get; set; }
    public String ObjectTable { get; set; }
    public String PropName { get; set; }
    public int PropType { get; set; }
    public String PropStringValue { get; set; }
    public Double PropDoubleValue { get; set; }
    public int PropIntValue { get; set; }
}


sql = Sql.Builder.Append("WHERE ObjectID=@0 AND ObjectTable=@1 AND PropType<>@2 ", this.box_CMSID, "TSelectiveBox", 4);
      sql.Append("ORDER BY PropName ASC;");

foreach (TExternalProp item in petaDb.Fetch<TExternalProp>(sql))
{
    myViewModel.ObCol_BoiteInstructions.set_values(item.PropName, item.PropType, item.PropStringValue, item.PropDoubleValue, item.PropIntValue);
}

Value in the database is 3.2, cast return 3.2000000476837158 in PropDoubleValue member. I need to get exactly the same value as it is in the database. Any idea ?

Solution :

MS Access Single Real = float type in C#. MS Access Double Real = double type in C#

  • 3
    Culture affects how numbers are displayed, not how they're stored. I'd be surprised if that had anything to do with it. It might be the other way around. The value you're getting back is what's in the database, but the way you're seeing it displayed in Access makes it look like it's 3.2. I'd verify every assumption before figuring out what to fix. – Scott Hannen Jul 03 '19 at 20:01
  • 1
    @ScottHannen is right. You are mixing up displayed and stored values, or your Petapoco does something behind the scene. – Gustav Jul 03 '19 at 20:05

1 Answers1

1

I was able to replicate this if the property is a Double, as you have it above, but the field in the Access database is defined as a single:

Access

Try changing your property definition to Single and see if that fixes things.

Edit: Corrected my capitalization on type names.

asherber
  • 2,508
  • 1
  • 15
  • 12