Hi everybody!
I have question about setting decimal symbols... In some countries,
for example in my country we use comma for decimal symbol, but
in in some other countries it is decimal point. The problem is when
I use comma and want to save data in database.
For example if i want to save number 4,50 it saves like 450, but
if i write 4.50 it regulary saves the number in that format.
My question is how to make to program knows what to act if my app
is working on system where decimal symbol is comma or decimal point.
Or should i use only comma and when saving data i just parse the
number and replace comma with point?
Arne Vajhøj - 21 Feb 2008 23:42 GMT
> I have question about setting decimal symbols... In some countries,
> for example in my country we use comma for decimal symbol, but
[quoted text clipped - 6 lines]
> Or should i use only comma and when saving data i just parse the
> number and replace comma with point?
You can either explicit specify CultureInfo for the
Parse or if you have really special requirements
explicit specify a NumberFormatInfo.
Arne
Jon Skeet [C# MVP] - 21 Feb 2008 23:49 GMT
> I have question about setting decimal symbols... In some countries,
> for example in my country we use comma for decimal symbol, but
[quoted text clipped - 6 lines]
> Or should i use only comma and when saving data i just parse the
> number and replace comma with point?
Don't specify the number as text at all when you pass it to the
database - use a parameterised command, and leave it as a number.

Signature
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
World class .NET training in the UK: http://iterativetraining.co.uk
Michael Nemtsev [MVP] - 22 Feb 2008 00:00 GMT
Hello Joza,
it's called "turkey test" http://www.moserware.com/2008/02/does-your-code-pass-turkey-test.html
just use the .Parse with NumberFormatInfo.Invariant as were recommended
---
WBR,
Michael Nemtsev [.NET/C# MVP] :: blog: http://spaces.live.com/laflour
"The greatest danger for most of us is not that our aim is too high and we
miss it, but that it is too low and we reach it" (c) Michelangelo
J> Hi everybody!
J>
J> I have question about setting decimal symbols... In some countries,
J> for example in my country we use comma for decimal symbol, but
J> in in some other countries it is decimal point. The problem is when
J> I use comma and want to save data in database.
J> For example if i want to save number 4,50 it saves like 450, but
J> if i write 4.50 it regulary saves the number in that format.
J> My question is how to make to program knows what to act if my app
J> is working on system where decimal symbol is comma or decimal point.
J> Or should i use only comma and when saving data i just parse the
J> number and replace comma with point
Joza - 22 Feb 2008 00:16 GMT
> Hello Joza,
>
> it's called "turkey test"
> http://www.moserware.com/2008/02/does-your-code-pass-turkey-test.html
>
> just use the .Parse with NumberFormatInfo.Invariant as were recommended
can you provide me some piece of code how to do that?
Thnx.
Michael Nemtsev [MVP] - 22 Feb 2008 00:29 GMT
Hello Joza,
there are sample in the article I posted http://www.moserware.com/2008/02/does-your-code-pass-turkey-test.html
I recommend to read that article
---
WBR,
Michael Nemtsev [.NET/C# MVP] :: blog: http://spaces.live.com/laflour
"The greatest danger for most of us is not that our aim is too high and we
miss it, but that it is too low and we reach it" (c) Michelangelo
J> Michael Nemtsev [MVP] wrote:
J>
>> Hello Joza,
>>
[quoted text clipped - 3 lines]
>> just use the .Parse with NumberFormatInfo.Invariant as were
>> recommended
J> can you provide me some piece of code how to do that?
J>
J> Thnx.
J>
Joza - 22 Feb 2008 10:50 GMT
> Hello Joza,
>
> there are sample in the article I posted
> http://www.moserware.com/2008/02/does-your-code-pass-turkey-test.html
> I recommend to read that article
> ---
Yes, i have read that article, but if i quite well understand i must
treat numbers like strings to use NumberFormatInfo or what?!
That it very confusing for me!
Jon Skeet [C# MVP] - 22 Feb 2008 07:47 GMT
> it's called "turkey test" http://www.moserware.com
> /2008/02/does-your-code-pass-turkey-test.html
>
> just use the .Parse with NumberFormatInfo.Invariant as were recommended
Why do that when the aim is to get the number into a *database*? That's
what db command parameters are for :)

Signature
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
World class .NET training in the UK: http://iterativetraining.co.uk
Arne Vajhøj - 23 Feb 2008 01:24 GMT
>> it's called "turkey test" http://www.moserware.com
>> /2008/02/does-your-code-pass-turkey-test.html
[quoted text clipped - 3 lines]
> Why do that when the aim is to get the number into a *database*? That's
> what db command parameters are for :)
True.
But before he can do that he need to get it as a number. Which is
where the parse is needed.
Arne
Jon Skeet [C# MVP] - 23 Feb 2008 07:29 GMT
> >> it's called "turkey test" http://www.moserware.com
> >> /2008/02/does-your-code-pass-turkey-test.html
[quoted text clipped - 8 lines]
> But before he can do that he need to get it as a number. Which is
> where the parse is needed.
There's no indication from the OP's question that he has it as a string
to start with, as far as I can tell.

Signature
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
World class .NET training in the UK: http://iterativetraining.co.uk
Arne Vajhøj - 24 Feb 2008 17:30 GMT
>>>> it's called "turkey test" http://www.moserware.com
>>>> /2008/02/does-your-code-pass-turkey-test.html
[quoted text clipped - 9 lines]
> There's no indication from the OP's question that he has it as a string
> to start with, as far as I can tell.
The original post was not very specific.
I got associations to the classic:
sqlstr = "INSERT ... VALUES(...," + double.Parse(tb.Text) + ",...)";
But maybe it was more hallucinations than associations ...
:-)
Arne