Managing culture issues in .NET programming, a challenge for programmer – Handling Number parsing

It is a challenging job for software companies and developers to deal with culture depe software companies india

It is a challenging job for software companies and developers to deal with culture dependent number parsing say, string to decimal or string to double etc. If these cases are not handled properly, it breaks the system anytime. ASP.NET software companies should aim at writing culture-safe and managed code that safe guards your applications from culture related issues.

What is number parsing?

All numeric types have two static parsing methods, TryParse and Parse, those are used to convert the string representation of a number into a numeric type.

Difference between TryParse and Parse is that TryParse method returns false whereas, the Parse method throws and exception if operation fails.

string numberStringRep = "35.88";

double number = double.Parse(numberStringRep);

Formatting conventions of a particular culture is always used by the Parse operation. If culture is not specified by passing a CultureInfo or NumberFromatInfo object, the culture associated with the current thread is used.

NumberFormat.NumberDecimalSeparator property is used to find the decimal separator string used by a culture.

// Returns: "."

new CultureInfo("en").NumberFormat.NumberDecimalSeparator;

// Returns: ","

new CultureInfo("es").NumberFormat.NumberDecimalSeparator;

// Returns: "."


// Returns: "<depends on the current culture>"


Why is it difficult to manage?

If number parsing from string to double is used in any application with multiple culture, developers in software companies should be cautious about the usage and probable issues associated.

An example, Cultures like German, French, Canadian, Spanish, etc., uses ‘,’ comma as a decimal separator whereas en-us uses ‘.’ dot as a decimal separator.

These are the cases when it becomes difficult to parse numbers from one culture to other.

Solution is to specify one rule for application like work with ‘.’ decimal separator or developer choice. One should also know the culture of the string being parsed from or decimal separator of that culture. Using this information, developer can easily manage them.

Common mistakes by programmers

Issue arises in number parsing when Culture gets change run time.

Let us understand this by an example. There is a potential bug in follwoing code, can you spot it?

Thread.CurrentThread.CurrentCulture = new CultureInfo("es");

string numberStringRep = "35.888";

double number = double.Parse(numberStringRep);

One must have realized that the parse call throws a FormatException. This is due to the current culture is Spanish and it uses “,” as the decimal separator whereas the string being parsed uses the “.” Dot as a decimal separator.

There are two ways to solve this problem:

  • Set the current culture to one with the correct number format for all Parse() calls.

    This option is tempting and developer should be very careful with this method as the current culture is used in other areas as well than just the parse methods. It can break other code.

    An example of this is the ToString() method, which also uses the current culture to determine its output:

    Thread.CurrentThread.CurrentCulture = new CultureInfo("en");

    35.88.ToString(); // Returns "35.88"

    Thread.CurrentThread.CurrentCulture = new CultureInfo("es");

    35.88.ToString(); // Returns "35,88"

  • Use overload that can be used to specify the culture to use for each Parse() call individually

    This option is safer unless developer is pretty sure to change the culture for all methods.

    string numberStringRep = "35,88";

    double number = double.Parse(numberStringRep, new CultureInfo("es"));

     Use following code snippet to identify the culture of number.

    double ResultVal;

    if (double.TryParse("75,89855",NumberStyles.Float, new CultureInfo("de-de"), out ResultVal))


    double number = double.Parse(ResultVal.ToString(),CultureInfo.InvariantCulture);

    } //Output: 75.89855

     If culture is not known to the developer and knows a specific decimal separator and still wants to convert decimal number, use following code snippet.

    // get a temporary culture (clone) to modify

    var resci = CultureInfo.InvariantCulture.Clone() as CultureInfo;

    resci.NumberFormat.NumberDecimalSeparator = ",";

    decimal number = decimal.Parse("1,2", resci);

    MessageBox.Show(number.ToString()); //Output: 1.2

    When developer passes a CultureInfo instance to parse method, an overload method is called that takes an IFormatprovider instance. The culture’s NumberFormat property is of type NumberFromatInfo which also implements IFormatProvider.

    This means that instead of supplying a culture, developer could also pass its NumberFormat property to the parse methods:

    string numberStringRep = "35.88";

    double number = double.Parse(numberStringRep, new CultureInfo("en").NumberFormat);

Managing culture issues in .NET programming, a challenge for programmer –String comparison

ASP.NET software companies or developers find it challenging to manage String operations like sortin

Software outsourcing companies in India


ASP.NET software companies or developers find it challenging to manage String operations like sorting, comparison etc. if it is culture dependent. Such issues are difficult to troubleshoot and it has potential to break the system.  

What is StringComparison?

The StringComparison is enumeration that is used to specify what string comparison should use among the options available.

  • Current culture or the invariant culture
  • Word or ordinal sort rules
  • Case-sensitive or case-insensitive

Developer passes the InvariantCulture object to a method that has aCultureInfo parameter, such as

  • Compare(string strnameA, string strnameB, bool ignoreCasetype, CultureInfo culture)

    This function compares two specified String objects, ignoring or honoring their case, and using culture-specific information to influence the comparison

    This returns an integer that indicates their relative position in the sort order.

    Below example shows how to use StringComparision.

    string stringname1 = "sister";

    string stringname2 = "Sister";

    // Cultural (linguistic) comparison.

    intStrresult=String.Compare(stringname1,stringname2,StringComparison.InvariantCultureIgnoreCase, System.Globalization.CultureInfo.InvariantCulture);
    //output: 0

  • Equals(string strA, string strB, CultureInfo culture)

    This function compares two specified String objects, using culture-specific information to influence the comparison.

    This returns a Boolean value true if both value are same else returns false.

    Below example shows how to use Stringcomparision for this.

    string stringname1 = "case";

    string stringname2 = "Case";

    bool result = String.Compare(stringname1, stringname2, System.Globalization.CultureInfo.InvariantCulture);
    //output: false
    //Output: true

Here, ‘InvariantCultureIgnoreCase’ is used to compare a string using culture-insensitive sort rule, the invariant culture, and ignoring the case of string being compared.

And ‘InvariantCulture’ used to compare strings using culture-sensitive sort rules and the invariant culture.

Why is it difficult to manage?

In normal cases, String comparison is not an issue. However the issue arises while using culturally sensitive routines in places. It is difficult to manage string comparison where multiple culture is used in one project.

 In Turkish culture, for most Latin alphabets, the letter i (Unicode 0069) is the lowercase version of I (Unicode 0049). The Turkish alphabet, however, has two versions of the letter I, one with a dot and one without.

English culture1 – i (u0069) <-> Turkish – i(u0130)

English culture1 – i (u0069) <-> English – I(u0049)

English culture1 – I (u0049) <-> Turkish – I(u0131)

Here is some code that demonstrates what this mean:

Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");

Console.WriteLine("Culture = {0}", Thread.CurrentThread.CurrentCulture.DisplayName);

Console.WriteLine("(file == FILE) = {0}", (string.Compare("file", "FILE", true) == 0));

Thread.CurrentThread.CurrentCulture = new CultureInfo("tr-TR");

Console.WriteLine("Culture = {0}",Thread.CurrentThread.CurrentCulture.DisplayName);

Console.WriteLine("(file == FILE) = {0}", (string.Compare("file", "FILE", true) == 0));


//Culture = English (United States)

//(file == FILE) = True

//Culture = Turkish (Turkey)

//(file == FILE) = False

Here, solution and recommendation is to use ‘InvariantCulture’ if developer knows the criteria of the application, whether it includes different cultures or not.

Common mistakes by programmers

  • The content of the code which relies on default culture values make no any sense to the code. It is difficult to know whether developer actually meant an ordinal comparison of two strings or whether a case sensitive difference as shown in below example.


    string strprotocol = “HTTP”;
    if(!String.Equals(strprotocol, “http”))
            throw new InvalidOperationException();

    Below solution makes it clear that comparison is invariant (if application is for multiple cultures) or current/ordinal(not for multiple culture) culture one and differences in case are ignored.

    string strprotocol = “HTTP”;
    if(!String.Equals(strprotocol, “http”, StringComparison.InvariantIgnoreCase))
              throw new InvalidOperationException();


If software development company or developer is writing an application to run on multiple locales, even if there is no globalization or localization logic in the software, software development companies or developers should be knowing about these issues to make sure that the code functions properly in all scenarios.

It is suggested to consider following points during StringComparison.

  • One should use an overload of the String.Equals method to test equality of two strings.
  • One should use the CompareTo and String.Compare methods to sort strings and not to check equality.
  • One should use any of the culture to compare strings.
  • OrdinalIgnoreCase and StringComparison.Ordinal use the binary values directly, and are best suited for matching. One can use one of these, when he is not sure about comparison settings.
  • One should not use culture-sensitive formatting to persist numeric data or symbolic data or date and time data in string form.
  • In most cases, one should use string operations based on InvariantCulture. Persisting linguistically meaningful but culturally agnostic data is an exception.


Managing culture issues in .NET programming, a headache for programmer – TimeZone Object

A time zone is a region on Earth with uniform standard time (UT) and have a legally defined borders

Software outsourcing companies India


A time zone is a region on Earth with uniform standard time (UT) and have a legally defined borders which coincide with the border of country or some subdivision for commercial, legal and social purposes. 15 longitudinal degrees, the time changes by one hour. Thus, there are 24 time zones in the world. Over the period, local governments of various countries have altered, accepted or rejected GMT (Greenwich Mean Time) as they saw fit per their country’s requirements.

Custom software that deals with varying time zone and date time calculations are prone to errors if software companies do not deal with TimeZone and DateTime properly with accuracy. Managing TimeZone and DateTime objects is challenging job for .NET developers in software companies.

What is TimeZone Object?

TimeZone object in .NET framework represents the current local time zone.

A time zone is a geographical region in which the same standard time is used. Programmer (Software Developer) can use the TimeZone class of .NET Framework to retrieve information about the current time zone and to convert local time to Coordinated Universal Time (UTC) or vice versa. Inheritance hierarchy is System.Object - > System.TimeZone.

Below is the syntax to get the local time zone and based on that the current Coordinated Universal Time (UTC) is retrieved.

TimeZone {localZone} = TimeZone.CurrentTimeZone;

DateTime {currentUTC} = localZone.ToUniversalTime( currentDate );

The format of the date and time string in time zone will be ISO-8601 as shown below.


Date: YYYY-MM-dd, Time:, Time zone: Z for UTC

There is lot of flexibility in the ISO-8601 format for example, we could have easily replaced the ‘Z’ at the end with a proper time zone offset like -0530 (India).

Why is it difficult to manage?

Many systems are dependent on keeping accurate time. The problem arises when time changes due to daylight savings like moving the clock forward or backwards. Software applications are so dumb that they don’t understand such human actions!

Common mistakes by programmers

Issue arises when Time zone gets changed

Let us understand this by an illustration. Assume that the customer’s main business is out of USA and their servers are hosted in France. The customer has their employees spread across multiple countries (ex: India, Indonesia, Japan and Canada).

Converting date and time string values back and forth between different cultures normally causes an issue in software applications and break them.

Solution: During implementation, when you are referring to an exact time, persist the time according to a unified standard that is not affected by daylight savings or any such actions. (GMT and UTC are equivalent with this regard, but it is preferred to use the term UTC. Notice that UTC is also known as Zulu or Z time.)

Architecture for the solution looks as shown in the below picture, showing what date time format is passed between different layers.

                               Software outsourcing companies India


Developers are advised to apply some basic rules between multiple layers.

  • Database: Everything that goes in and out is going to be UTC
  • Server: Everything that goes in and out is going to be UTC
  • The client (front-end) : Everything that goes in and out is going to be UTC

The time zone offsets are not always an integer number of hours (for example, Nepal uses UTC+05:45, Indian Standard Time is UTC+05:30).


TimeZone objects are challenging to manage and have potential to drive technical team crazy and insane. Proactive approach and following best practices can help programmers and software development companies to combat these challenges.

  • Timestamps are suggested to be stored in UTC
  • Date and time math should be performed using library
  • Standard time offset should be used 

Managing culture issues in .NET programming, a headache for programmer – DateTime object

Programming is fun and gives the sense of accomplishments to programmers and developers. First it is

Software outsourcing companies India


Programming is fun and gives the sense of accomplishments to programmers and developers. First it is due to sheer joy of creation and solving business problems. As the child takes pride in mud pie, so the programmers and software companies do enjoy building things and solving the business problems.  Programming sounds easy however it requires a hell lot of thinking, thinking and thinking. Common areas programmer fall prey for are handling different culture issues in programming. There are various scenarios that one needs to address while developing application for multiple or different cultures. Some of the areas are:

  • Handling Date-Time values
  • Ideal solution for handling time zone.
  • String operations
  • Handling numeric values

What is DateTime Object?

DateTime object is used to express a date and time of the day in programming. This is used to perform calculation and comparisons of DateTime instance of same time zone.

There are different ways to instantiate a DateTime object.

  • DateTime {Name of class} = new DateTime(2016, 10, 10, 5, 05, 05) ;

    This is a DateTime constructor that is called to create a date with specific year, month, day, hour, minute and second.

  • DateTime {Name 1} = DateTime.Now;

    DateTime {Name 2} = DateTime.Utc;

    DateTime {Name 3} = DateTime.Today;

    Assigns the current date and time, the current (Coordinated Universal Time) UTC date and time and current date to the three new variables.

  • string {string name} = “10/10/2016 5:30:53 AM”

    DateTime {date name} = DateTime.Parse(dateString,


    This parses a date string and converts it to a DateTime value. The Parse, ParseExact, TryParse, and TryParseExact methods are used to convert string to its equivalent date and time values.

Why is it difficult to manage?

It is difficult to manage DateTime when we are performing calculation or comparison on DateTime object which are from different time zones.  Managing DateTime object of two different time zones is one of the challenging job c# software companies consider.  Common difficulties for software programmers in managing DateTime are below.

  • Comparison or calculation of DateTime object of two different time zones

    If one DateTime object contains machine local date/time and another object contains server date/time and suppose server is dealing with French time zone.

    Comparison on DateTime object may not yield a correct value in this case. Calculations like add date/time/days/ year also do not return accurate values and throws unexpected calculation errors.

    Solution is to have a date representation in Universal format (GMT) always – this may not be practical though in all cases. When date representation is in universal format, every day has fixed length and there are no time-zone offsets to deal with that makes it easy to perform any calculations or comparison.

    While performing any calculation between dates, it is recommended by software companies to convert the local time value to universal time first and then perform the calculations and convert back to achieve desired accuracy. Following is an illustration of conversin.

    DateTime {name} = DateTime.Parse("Oct 03, 2016 12:00:00 PM").ToUniversalTime();

    date = date.AddHours(3.0).ToLocalTime();

  • Converting DateTime value of machine time zone or date in string format to DateTime value of other time zone is difficult to handle for developers.

    Here, solution is to call the ‘Parse’ and ‘ToString()’ only after setting CultureInfo to CultureInfo.InvariantCulture. The invariant culture is culture-insensitive; it is associated with the English language but not with any country/region.

    string {DateInString} = "5/1/2008 8:30:52 AM";
    DateTime {date} = DateTime.Parse(dateString, System.Globalization.CultureInfo.InvariantCulture);

    This technique ensures that the underlying time and date values do not change when the date is read or written by developers from different cultures.

Common mistakes by programmers

Following are common mistakes while dealing with DateTime objects.

  • Dealing with ‘Now’

    ‘Now’ method is commonly used to get the current time. The value returned by the ‘Now’ method is in the current machine time-zone context and cannot be treated as an immutable value.

    Converting times to be stored or sent between machines into UTC (Universal Time) is common practice using following method.

    DateTime {date} = DateTime.Now.ToUniversalTime();

    Resulted value would be off by an hour if called during extra hour occurring during the daylight saving.

    Solution is to use ‘UTCNow’

    Instead, call the DateTime.UtcNow function directly. This code will always have the proper 24-hour-day perspective, and then be safely converted to local time.

    DateTime {timeval} = DateTime.UtcNow;

  • Not using ‘InvariantCulture’ with DateTime

    While dealing with parses method to convert it string date value to DateTime value, it considers machine culture. Issue arises when a developer has an application that runs in any of the culture and have date time conversion in the app.

    For example, application has a DateTime picker to show a date with the specific format. In code behind parses a string date to DateTime value using following code snippet.

    string {dateString} = "10/1/2016 8:30:52 AM";

    DateTime {date} = DateTime.Parse(dateString);

    This scenario will generate an unexpected error while dealing with different culture.

    Solution is to use ‘InvariantCulture’ method. The following example uses the invariant culture to persist a DateTime value as a string.

    //Parse the stored string.

    DateTime {dt} = DateTime.Parse("Thur, 1 October 2016 20:34:16 GMT", CultureInfo.InvariantCulture);

    It is also easy to parse the string and display its value by using the formatting conventions of the French (France) culture.

    // create a French (France) CultureInfo object.

    CultureInfo {frFr} = new CultureInfo("fr-FR");

    // Displays the date formatted for the "fr-FR" culture.

    MessageBox.Show("Date formatted for the " + frFr.Name + " culture: " + dt.ToString("f", frFr));

    // Output: Date formatted for the fr-FR culture: mardi 1 octobre 2016 20:34:16

    The Parse, ParseExact, TryParse, and TryParseExact methods are used to convert string to its equivalent date and time value.

    You can also use DateTime.TryParse Method (String, DateTime) that converts the specified string representation of a date and time to its DateTime equivalent and returns a value that indicates whether the conversion succeeded and does not throw an exception if the conversion fails.


  • Developer should understand that DateTIme comparison and calculation are correct and meaningful if they are representation of points of time of same time zone perspective.
  • In general, it is recommended to use a Universal (GMT) time value if possible so that one gets the required accuracy.
  • Always parses string date to DateTime value with using ‘InvariantCulture’ when dealing with different culture for DateTime format.

Top 10 Notable software bugs re-enforces the Software Quality

&amp;nbsp; Many software outsourcing companies ignore the most important stage of software development l

10 notable software bugs - software outsourcing companies India


Many software outsourcing companies ignore the most important stage of software development life cycle that is Software Quality (Testing). Software Quality Assurance is predominant and unrivalled step in providing quality and successful product to the customer. It is a known myth that the QA process is performed as a last step of software development process however QA starts from the beginning of the project. Quality of a product is backbone to its success. Following case studies provides important insight on how less quality product can create havoc and ultimately impacts the business performance and its brand image.


1. Apple Maps – A vision to replace Google Map

According to (NYtimes, 2016) company decided to replace Google Map with its own mapping system back in the year 2012 with Apple iOS 6 update. Unfortunately, it did not work the way it was planned resulting in one of the most epic failure of the mobile computing. The software was missing entire towns and some locations were entirely misplaced. Company invested a lot of money in building the same and then replacing the software.


2. Windows : the Blue Screen of Death

Per (Geek, 2016),  most of software professionals might have witnessed this bug. This bug was due to issues with hardware driver software. This causes the Windows to crash and stop working. The only solution it was believed to have was to start the computer. This can potentially lead to data loss.

                                 blue screen bug, custom software development companies India


3. Software Security flaw in OLA’s Mobile App

Mobile computing and usage is increasing at very high pace. Users have started using Mobile apps for various reasons like online shopping, booking and online banking. Security is paramount for safe and secure user experience.

Ola cabs app allows easy and fast cab or a taxi booking.  Per (Times, 2016),the two programming flaws allowed unethical individuals with basic computer and programming knowledge to enjoy unlimited free cab rides at the expenses of Ola company. This was due to lack of implementation of security protocols or token validation issues.


4. HSBC business banking glitch

Financial transactions are highly prone to hacking and security breaches for financial gain and misuse. Security is an unrivalled important factor for online banking and transactions. As mentioned by (BBC, 2016), HSBC customers could not access their internet banking for several hours due to cyber-attack. The company website and portal was hit by a denial of service attack, which is caused by overload of network traffic by cyber attackers.


5. Nissan’s Airbag Software Flaw / Malfunction

(Bidnessetc, 2016) takes a note of Nissan’s Airbag software flaw that resulted in 4 million Nissan cars being recalled. The software had safety issues where passenger air bags or seat belts could fail in a crash that can lead to serious fatalities or injuries. As per The Telegraph news, Nissan recalled approx.. 3.5 million cars due to airbag issues and it caused heavy loss to the company.


6. US and Canada : Blackout for 50 Million due to Race Condition Bug

As per the sources of PC Authority, (PCAuthority, 2016), on August 14, 2003, a blackout across eight US states and Canada affected 50 million people. “A race condition bug”, a situation when two separate threads of a single operation uses the same code element, was culprit behind this software flaw. This crashed a system without proper synchronization and resulted 256 power plants offline. This failed primary server within 30 minutes due to unprocessed events queue. Backup system also failed within few minutes.

FirstEnergy’s computerized Energy Management System is known as the direct cause for the blackout that cut off electricity to 50 million people in 8 states and Canada.



7. Computer virus due to World Of Warcraft game

World Of Warcraft (Wow) is a popular game of adventure in the fantasy world. (BBC, BBC NEWS | Technology | Deadly plague hits Warcraft world, 2016) reported a security breach in the game where new Hacker, the god of Blood, hit the game and took the “computer virus” thing literally. The virus, “Corrupted-blood” had the ability to kill off weaker characters thus interrupting the game. This infected many workstations as well.



8. Loss of $440 million in 45 minutes - Knight Capital Group

The Knight Capital Group was an American global financial services firm with great reputation in the market, engaging in electronic execution, market making, and institutional sales and trading. Per (Fortune, 2016), It took only 45 minutes to blow off the company reputation and capital due to a computer software bug. Between 9:30 am to 10 am EST, 1 August 2012, the company’ software bought high and sold low on 150 different stocks. By the time software stopped further bleeding, company had already lost $440 million on trades. Company’s market capital was just $296 million then and loss was about four times its 2011 net income. In addition to this, company’s stock price dropped 62% in just one day according to Bloomberg Businessweek.


9. Starbucks Breakdown caused by Software Bug

Starbucks Corporation is an American coffee company and coffee house chain founded in Seattle, Washington in 1971.

As noted by (Yahoo, 2016), In April 2015, Starbucks had to close roughly 60% of their stores located worldwide due to software failure. Thousands of stores in North America were unable to proceed with their business due to software bug. Software flaw did not allow cash registers to process orders and take payments. The software malfunction was very high and it affected roughly 13,500 locations in US and Canada.


10. Swiss Bank : Software Glitch Sent Bank Statements to the Wrong People

According to (AbcNews, 2016), a Swiss bank found themselves in critical situation in 2014 when they discovered that their software system has sent bank statements addressed to wrong people. Many customers reported receiving along with their statement, other statements comprising of details for other bank patrons.



These case studies are examples of what havoc a software bug can create. Software can be helpful in automating your business processes however they are potentially dangerous if it goes buggy. It can impact your business big time. Software outsourcing companies in India should emphasize software quality and should include this from the beginning of software development.



AbcNews. (2016, 10 1). Swiss Bank Giant UBS Hit by LoveBug Strain - ABC News. Retrieved from AbcNews:

BBC. (2016, 10 1). BBC NEWS | Technology | Deadly plague hits Warcraft world. Retrieved from BBC:

BBC. (2016, 10 1). HSBC online banking is 'attacked' - BBC News. Retrieved from BBC:

Bidnessetc. (2016, 10 1). Nissan Under Investigation By U.S As Two Of Its Vehicles Are Called Back. Retrieved from Bidnessetc:

Fortune. (2016, 10 1). Why Knight lost $440 million in 45 minutes. Retrieved from Fortune:

Geek, H.-t. (2016, 10 1). Everything You Need To Know About the Blue Screen of Death. Retrieved from howtogeek:

MIS-ASIA. (2016, 10 1). MIS-Asia - Top software failures of 2015/2016. Retrieved from mis-asia:

NYtimes. (2016, 10 1). Apple’s New Maps App Is Upgraded, but Full of Snags - Review - The New York Times. Retrieved from nytimes:

PCAuthority. (2016, 10 1). Ten of the world's most disastrous IT mistakes - PC & Tech Authority. Retrieved from PC Authority:,ten-of-the-worlds-most-disastrous-it-mistakes.aspx

Times, T. E. (2016, 10 1). Taxi aggregator Ola hit by tech glitches that allow free rides - The Economic Times. Retrieved from economictimes.indiatimes:

Yahoo. (2016, 10 1). Starbucks breakdown shows how registers have evolved. Retrieved from Yahoo: