MarkPflug/Sylvan.Data.Excel

Decimal value converted to string

ankitsataparaTR opened this issue · 3 comments

Hi @MarkPflug

I am facing one issue while reading the decimal value "0.000033502" using sylvan excel reader, When trying to read the mentioned value it returns as "3.3502E-05". Please refer below images for reference, I also attached the excel file I am using to reproduce the same.
Later in code when we are trying to convert it to decimal at that point it's giving me an error.
Please will you be able to look into this.

image

image

Decimal Value Problem.xlsx

Later in code when we are trying to convert it to decimal at that point it's giving me an error.

I'd need to see your code to know what's going on exactly. However, if you use ExcelDataReader.GetDecimal(int ordinal) to read this value it returns the value as a System.Decimal type. You can also provide NumberStyles.AllowExponent when converting to decimal: decimal value = decimal.Parse(strVal, NumberStyles.Number | NumberStyles.AllowExponent, null);

I don't think there is anything for me to fix here.

@MarkPflug
Thanks for your reply. I agree we can parse the decimal but the point is from the library it self we are getting values with E, which not able to parse into the numeric format.

image

Can you please look at this point for code where that decimal value gets converted to the string which contains E in it?
If you refactor the first switch case than it will be a very helpful.

Thanks

You still haven't shown me any of your code. I won't be changing anything on my end without first understanding how you're using my library. I'm quite certain that there are ways for you to work around this. The string "3.3502E-05" is a perfectly reasonable way to represent that value. I've already told you two ways to work around the issue. Please don't comment again, unless you are willing to share your code.