0

I have a string variable x with value 2.54, During the time of binding this value in to my ui it displays like 2,54. I know this is something related device's current culture. But i dnt know how to fix this issue. I am new to visual studio & and don't much about string formatting . Please anyone help me to fix this issue.

double x = 2.54;
displayValue = x.ToString(); // Here display value is the property which i bind in to UI. There is nothing much in my code.
WinPhone Artist
  • 280
  • 1
  • 2
  • 10
  • 5
    Posting the failing code is the better way to get a precise answer. – Steve Oct 08 '13 at 08:31
  • 1
    Search for c# dot coma problem on google you will get a lot of answers http://stackoverflow.com/questions/9160059/set-up-dot-instead-of-comma-in-numeric-values – Manvik Oct 08 '13 at 08:41
  • Yes. No matter what the device culture is, I always want to display it in US culture. – WinPhone Artist Oct 08 '13 at 08:45

1 Answers1

1

What is your issue? That you want to display a number to the user by disregarding their selected locale?

If so, then you can probably use the invariant culture:

displayValue = x.ToString(CultureInfo.InvariantCulture);

This is a good bet for numbers that need to be consumed by other programs or embedded in generated source code. For dates it's nigh-useless.

To use a specfic locale, you can use e.g.

CultureInfo.GetCulture("en-us")

Generally you should respect the user's settings, though. When I have an app telling me how far I've run I would expect the number to match my regional settings.

Joey
  • 344,408
  • 85
  • 689
  • 683