Search This Blog

Showing posts with label CultureInfo. Show all posts
Showing posts with label CultureInfo. Show all posts

Sunday, August 12, 2018

Properly handle insertion of values of type Double into database, independently of CurrentCulture, in C#

if (row[column] is double)
{
    //properly deal with rational numbers - ALWAYS use the same (english - culture invariant) numbering format rules - otherwise data will differ between cultures
    //for example, portuguese uses , as thousand separator, while english uses a dot. This causes mySql to calculate different values form SUM(myColumn).

    var d = Convert.ToDouble(row[column]);
    value = d.ToString(CultureInfo.InvariantCulture);
}