0

How to convert form the following format 12,5242.25 to decimal 125242.25 reading a set of data from an excel workseet and am using some internally developed library to which i don't have access to, in order to map the worksheet to a POCO.

[ExcelObject("NameFromExcelOfDataCollection")
public class @MyClass
{
    ....
    
    [ExcelColumn(Name = "excel_column_name", format: "????")]
    public decimal MyNumber { get; set; }
   
    ....
} 

I found this .NET String.Format() to add commas in thousands place for a number which shows how to do it the other way arround.

  • `Console.WriteLine(decimal.Parse("12,5242.25"));` ? – TheGeneral Nov 04 '21 at 21:51
  • See [`decimal.TryParse`](https://learn.microsoft.com/en-us/dotnet/api/system.decimal.tryparse?view=net-5.0) methods. – Dmitry Nov 04 '21 at 21:51
  • @TheGeneral, the value is comming from an excel worksheet and I want to specify this during deserialization as format in some custom attribute –  Nov 04 '21 at 21:54
  • 2
    For what it's worth, this isn't what "comma-delimited" means. If I have a string that looks like `"Beans, 4.95, per lb, 04:00:00"` that's a comma delimited string - there are four fields in a record, with the fields delimited by commas (effectively 4 columns in a row (speaking database-ese)). What you are talking about is a "thousands separator" (not all cultures use a comma (for example, en-CA uses a comma, but fr-CA uses a space)). – Flydog57 Nov 04 '21 at 23:12
  • good comment, helps a lot –  Nov 05 '21 at 07:16

0 Answers0