0

Aarghhhhh!!! I just asked how to input numbers only and now I have the problem that when I insert a number with code such as:

tbNum.Text = Convert.ToString(double.Parse(tbPerc.Text));

The number is an int instead of a double. Therefore I get something like 5623 instead of 562,3. I have set InputScope to number if it helps. Thanks!!!

In facts I have some calculations inside the Convert.ToString method but this isn't relevant because the returned value of a calculation between doubles is double.

Cippo
  • 1,001
  • 4
  • 14
  • 26
  • 6
    So you are converting a string to a double that you convert to a string? aha... – f2lollpll Mar 13 '12 at 20:20
  • Take a look at [http://stackoverflow.com/questions/105770/net-string-format-to-add-commas-in-thousands-place-for-a-number](http://stackoverflow.com/questions/105770/net-string-format-to-add-commas-in-thousands-place-for-a-number) – Raj Ranjhan Mar 13 '12 at 20:31
  • Can you add a sample value that you are trying to convert? – Bryant Mar 13 '12 at 21:24

2 Answers2

0

I can't see the reason of converting the string to a double to a string, but if you insert 562.3 instead of 562,3 your example will work.

Dudemeister
  • 537
  • 4
  • 9
0

If you're using InputScope with Number set, then you're using the "." as decimal separator, not the "," (that's what appears in the keyboard)

As such, I assume your Windows Phone device / emulator is assuming the "," sign as a thousands separator (the en-US default, per example) and as such:

double.Parse("562,3") == 5623
double.Parse("562.3") == 562.3
Pedro Lamas
  • 7,185
  • 4
  • 27
  • 35
  • Do note that you should use `double.Parse("562.3", CultureInfo.InvariantCulture)` so that it will ignore the system wide CultureInfo and use an Invariant one (that has "." as decimal separator) – Pedro Lamas Mar 15 '12 at 16:11