Decimal Type converter error #1729
Replies: 19 comments
-
Is there a way to |
Beta Was this translation helpful? Give feedback.
-
Sorry I did not get you? Where shall this be applied? in Mapper ? |
Beta Was this translation helpful? Give feedback.
-
I'm saying, is there a way outside of CsvHelper to convert the string |
Beta Was this translation helpful? Give feedback.
-
Because |
Beta Was this translation helpful? Give feedback.
-
Sorry its was supposed to be shown as 29.45 .. The actual text is 29.45. No ** |
Beta Was this translation helpful? Give feedback.
-
Oh, lol. What is the value of |
Beta Was this translation helpful? Give feedback.
-
CultureInfo.CurrentCulture = en-US var csvConfig = new CsvConfiguration(CultureInfo.CurrentCulture)
{
HasHeaderRecord = false,
Delimiter = ",",
MissingFieldFound = null,
};
using (var reader = new StringReader(line))
using (var csv = new CsvReader(reader,csvConfig))
{
while (csv.Read())
{
csv.Context.RegisterClassMap<VendorMap>();
vendorList.Add(csv.GetRecord<Vendor>());
}
} |
Beta Was this translation helpful? Give feedback.
-
There must be something else I'm missing. This works: void Main()
{
var s = "FLORENS,ML-CROWL-01,RNT1111585,05/31/2020,05/01/2020,05/31/2020,DFSU4055875,05/01/2020,05/31/2020,07/31/2019,,101,0.95,31,29.45";
var config = new CsvConfiguration(CultureInfo.GetCultureInfo("en-US"))
{
HasHeaderRecord = false
};
using (var reader = new StringReader(s))
using (var csv = new CsvReader(reader, config))
{
csv.Context.RegisterClassMap<FooMap>();
csv.GetRecords<Foo>().ToList().Dump();
}
}
private class Foo
{
public decimal Decimal { get; set; }
}
private class FooMap : ClassMap<Foo>
{
public FooMap()
{
Map(m => m.Decimal).Index(14).TypeConverterOption.NumberStyles(NumberStyles.Number);
}
} |
Beta Was this translation helpful? Give feedback.
-
I really donno what is missing. I just copy pasted your code. |
Beta Was this translation helpful? Give feedback.
-
That is showing the text is empty. It looks like index 10 is the only empty one. What is the mapping for index 10? |
Beta Was this translation helpful? Give feedback.
-
Map(m => m.EquipmentDropoffDate).Index(10); EquipmentDropoffDate is of datetime? In the input this index is empty but i have made this nullable is it still a problem ? Actually ... there was problem with datetimeconverter as well. After I made all the datetime properties to nullable, then, that error did not appear |
Beta Was this translation helpful? Give feedback.
-
Everything good now? |
Beta Was this translation helpful? Give feedback.
-
Unfortunately No... can you please also include index 3,4,10,14 and try on your side? |
Beta Was this translation helpful? Give feedback.
-
Can you give me your class and mapping definitions so I can try the full thing? |
Beta Was this translation helpful? Give feedback.
-
Ok I think i got the problem. If i pass the data as string created like you have done, then, everything will work fine. However, if I read it from file and pass for some reason string value is going as "a,b,c,d" with quotes... your way is without quotes.. |
Beta Was this translation helpful? Give feedback.
-
Thank you for your help. I solved it.. Can you please delete your comment #1728 (comment) ? Actually it is a actual class i am using. Please delete it from public forum. |
Beta Was this translation helpful? Give feedback.
-
Posts with the class in them deleted. What was the fix? |
Beta Was this translation helpful? Give feedback.
-
Thank you so much. my string value was like following: var s = ""a,b,c,d,e,f""; where as, string you created was var j = "a,b,c,d,e,f"; I removed the quotes from string s ... That solved the problem. Thank you so much for your quick help and response. Your CsvHelper is awesome and helping me a lot. |
Beta Was this translation helpful? Give feedback.
-
Great. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I still get Decimal converter error. I am using 25.0.0
I have checked all your answers related to this. For example this
#1125 (comment)
Beta Was this translation helpful? Give feedback.
All reactions