From: Rolf M. <rm...@fa...> - 2008-04-07 03:06:19
|
Hello... I have a C# program that takes a currency (decimal 10,2) amount and stores it in a table. With the culture "EN_us", everything works fine: 7.99 appears in the table as 7.99. Now, if I change the culture to Finland (whose currency uses a comma as the decimal separator), I see that 7,99 appears as 799 in the table, and from that point everything goes downhill. Can someone please tell me where I can find some documents (or help) on resolving this issue? I really would appreciate it. |
From: Jiri C. <di...@ci...> - 2008-04-07 07:51:13
|
Can you show us piece of code? -- Jiri {x2} Cincura (CTO x2develop.com) http://blog.vyvojar.cz/jirka/ | http://www.ID3renamer.com |
From: YAMACO S. <ya...@ya...> - 2008-04-07 07:56:21
Attachments:
smime.p7s
|
I am afraid But I do not have a source code for .NET assembly. As I said it was supplied by another vendor. Ing. Karel Janeček, MBA ================================ = YAMACO Software = aplikační software, softwarové služby = Prostějovičky 79, 798 03 Plumlov, ČR = IČ 484 63 850, DIČ CZ6612301300 = tel./fax: 582 393 605 = tel.: +420 731 616 511 = http://www.yamaco.cz =============================== > -----Original Message----- > From: fir...@li... > [mailto:fir...@li...] > On Behalf Of Jiri Cincura > Sent: Monday, April 07, 2008 9:45 AM > To: For users and developers of the Firebird .NET providers > Subject: Re: [Firebird-net-provider] I've got decimal issues > with other > > > Can you show us piece of code? > > -- > Jiri {x2} Cincura (CTO x2develop.com) > http://blog.vyvojar.cz/jirka/ | http://www.ID3renamer.com > > -------------------------------------------------------------- > ----------- > This SF.net email is sponsored by the 2008 JavaOne(SM) Conference > Register now and save $200. Hurry, offer ends at 11:59 p.m., > Monday, April 7! Use priority code J8TLD2. > http://ad.doubleclick.net/clk;198757673;13503038;p?http://java .sun.com/javaone _______________________________________________ Firebird-net-provider mailing list Fir...@li... https://lists.sourceforge.net/lists/listinfo/firebird-net-provider |
From: Jiri C. <di...@ci...> - 2008-04-07 08:36:52
|
On 4/7/08, YAMACO Software <ya...@ya...> wrote: > I am afraid But I do not have a source code for .NET assembly. As I said > it was supplied by another vendor. > So ask vendor. When they found a bug, they can report it to here. -- Jiri {x2} Cincura (CTO x2develop.com) http://blog.vyvojar.cz/jirka/ | http://www.ID3renamer.com |
From: Rolf M. <rm...@fa...> - 2008-04-07 14:33:22
|
Jiri Cincura wrote: > Can you show us piece of code? > > CultureInfo ci = CultureInfo.CurrentCulture; NumberFormatInfo nfi = ci.NumberFormat; decimal decPrice, decCost; decPrice = decimal.Parse(pricePieces[0]); // pricePieces is a string array where I remove trailing currency sign string fbInsertString = "insert into tBooks values ('" + BookNbr + "', '" + Title.ToString().Replace("'", "''") + "', '" + Author.ToString().Replace("'", "''") + "', '" + ISBN + "', '" + Illus + "', '" + // Locn + "', '" + decPrice + "', '" + decCost + "', '" + ... |
From: Jiri C. <di...@ci...> - 2008-04-07 15:26:27
|
On 4/7/08, Rolf Marsh <rm...@fa...> wrote: > string fbInsertString = "insert into tBooks values ('" + > BookNbr + "', '" + > Title.ToString().Replace("'", "''") + "', '" + > Author.ToString().Replace("'", "''") + "', '" + > ISBN + "', '" + > Illus + "', '" + // > Locn + "', '" + > decPrice + "', '" + > decCost + "', '" + ... Use parameters(!), not composing query. Here you have 2 problems (except composing). 1. You're placing >'< around number. 2. The FB server is accepting only >.< as decimal separator so using >,< is mistake (that's why you get the wrong number). -- Jiri {x2} Cincura (CTO x2develop.com) http://blog.vyvojar.cz/jirka/ | http://www.ID3renamer.com |
From: Dean H. <dea...@dl...> - 2008-04-07 23:22:04
|
Rolf Marsh wrote: > CultureInfo ci = CultureInfo.CurrentCulture; > NumberFormatInfo nfi = ci.NumberFormat; > decimal decPrice, decCost; > > decPrice = decimal.Parse(pricePieces[0]); // pricePieces is a string > array where I remove trailing currency sign There are two problems here. This will actually, but you've also given us this code: > CultureInfo ci = CultureInfo.CurrentCulture; > NumberFormatInfo nfi = ci.NumberFormat; > decimal decPrice, decCost; > string x = > pricePieces[0].Replace(nfi.CurrencyDecimalSeparator, "."); > decPrice = decimal.Parse(x); Which will not work -- as you say, with a non-US culture (or at least, one that expects "," as the decimal separator, this'll throw an exception. Do not use this code, use the code above (where you just call "decimal.Parse" on the string itself). The second problem is this: > string fbInsertString = "insert into tBooks values ('" + > BookNbr + "', '" + > Title.ToString().Replace("'", "''") + "', '" + > Author.ToString().Replace("'", "''") + "', '" + > ISBN + "', '" + > Illus + "', '" + // > Locn + "', '" + > decPrice + "', '" + > decCost + "', '" + ... The code: string s = "blah" + decimal + "blah"; is equivalent to: string s = "blah" + decimal.ToString() + "blah"; By default, "ToString" uses the current culture, so this code would be using a comma as the decimal separator on a Finnish computer. Firebird only supports a period "." as the decimal separator, and that's why it doesn't work. The correct method, as Jiri points out, is to use parameterised queries (parameterised queries have many other benefits as well... you should never compose strings of SQL like that.) Here's a simple example: FbCommand cmd = new FbCommand( "INSERT INTO tBooks (price) VALUES (@price)", connection); cmd.Parameters.AddWithValue("@price", decPrice); cmd.ExecuteNonQuery(); Dean. |
From: Rolf M. <rm...@fa...> - 2008-04-07 16:02:41
|
When I try to convert the string to decimal using a >.< and the culture is non-US, I get a "string not in correct format" error. Code is: CultureInfo ci = CultureInfo.CurrentCulture; NumberFormatInfo nfi = ci.NumberFormat; decimal decPrice, decCost; string x = pricePieces[0].Replace(nfi.CurrencyDecimalSeparator, "."); decPrice = decimal.Parse(x); Because the non-US culture expects a >,< as the separator, it will not take the >.<. At one point (last week) I did get the data with a comma delimiter into the table, but don't remember how I did it... maybe make decPrice a string and let Firebird do the conversion? Also, can you point me to a doc that shows how to use parameters when building a query? I've always done it this way, not knowing whether it was right or wrong. Regards, Rolf Jiri Cincura wrote: > On 4/7/08, Rolf Marsh <rm...@fa...> wrote: > >> string fbInsertString = "insert into tBooks values ('" + >> BookNbr + "', '" + >> Title.ToString().Replace("'", "''") + "', '" + >> Author.ToString().Replace("'", "''") + "', '" + >> ISBN + "', '" + >> Illus + "', '" + // >> Locn + "', '" + >> decPrice + "', '" + >> decCost + "', '" + ... >> > > Use parameters(!), not composing query. Here you have 2 problems > (except composing). 1. You're placing >'< around number. 2. The FB > server is accepting only >.< as decimal separator so using >,< is > mistake (that's why you get the wrong number). > > |
From: Jiri C. <di...@ci...> - 2008-04-07 16:38:03
|
On 4/7/08, Rolf Marsh <rm...@fa...> wrote: > Also, can you point me to a doc that shows how to use parameters when > building a query? I've always done it this way, not knowing whether it was > right or wrong. Look at FbCommand.Parameters collection. Or just DbParameterCollection in MSDN. -- Jiri {x2} Cincura (CTO x2develop.com) http://blog.vyvojar.cz/jirka/ | http://www.ID3renamer.com |