Can this value be converted to Decimal?

Camillia
Camillia used Ask the Experts™
on
We have a multilingual application. One is Polish and we want to export data to excel. We get this error

System.ArgumentException: Input string was not in a correct format.Couldn't store <4 488,67> in 2 Column. Expected type is Decimal. ---> System.FormatException: Input string was not in a correct format

I tried this
var test = Convert.ToDecimal("4 488,67");

Open in new window


But still get an error....same one.

Anyway to convert a value like that to Decimal?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Chinmay PatelChief Technology Ninja
Distinguished Expert 2018

Commented:
Hi Camillia,

Get rid of the space and comma and try.

Regards,
Chinmay.
Software Team Lead
Commented:
what's the value represented by "4 488,67" ?? you're using comma "," not really a decimal point there.
I think the comma is decimal point in Polish. I'll ask my manager.
Starting with Angular 5

Learn the essential features and functions of the popular JavaScript framework for building mobile, desktop and web applications.

Chinmay PatelChief Technology Ninja
Distinguished Expert 2018
Commented:
Hi Camillia,

You are right. i just did a quick check and the comma is infact a decimal point.

Try this code:

  string culture = "pl-PL"; // Culture Code for Polish
            string value = "4 488,67"; 
            Console.WriteLine(Convert.ToDecimal("4 488,67", new CultureInfo(culture)));

Open in new window


Let me know if you need further help.

Regards,
Chinmay.
Thanks, let me see. I'll post back.
As always, thanks.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial