SCM

[#1011085] Money format is not set in accordance with the system locale format

View Trackers | Bugs | Download .csv | Monitor

Date:
2011-09-04 22:21
Priority:
3
State:
Closed
Submitted by:
Samuele Forconi (samueleforconi)
Assigned to:
Nobody (None)
Npgsql Version:
2.0.11
Category:
None
Group:
None
Resolution:
None
Summary:
Money format is not set in accordance with the system locale format

Detailed description
Description:
Using the money format with system locales that uses as decimal separator the character ',' and as thousand separator the character '.' produces wrong values inserted in the DB (money format works correctly with locales that uses as decimal separator the character '.' and as thousand separator the character ',').

System:
Windows XP, with current locale set as it-IT.
PostgreSQL 9.0 (postgresql.conf, lc_monetary = 'Italian_Italy.1252')
NPGSQL 2.0.11.0


Example of code used for debugging:

NpgsqlCommand = new NpgsqlCommand("UPDATE prices SET price = @price WHERE id = 1", conn);
decimal myMoney = 8.99m;
NpgsqlParameter np = command.Parameters.Add("@price", NpgsqlTypes.NpgsqlDbType.Money);
np.Value = myMoney;

Result: the row is updated but the amount of money is wrong (€899,00 instead of €8,99).

Some examples, setting:
myMoney = 8.99m I obtain in DB €899,00 (expected €8,99)
myMoney = 100m, I obtain in DB €100,00 (correct)
myMoney = 75.25m, I obtain in DB €7.525,00 (expected €75,25)

NPGSQL logging has shown these lines:

Entering NpgsqlParameterCollection.Add(@prezzo, Money)
Entering NpgsqlParameter.NpgsqlParameter(@prezzo, Money, 0, )
Set NpgsqlParameter.ParameterName = @prezzo
Set NpgsqlParameter.NpgsqlDbType = Money
Entering NpgsqlParameterCollection.Add(Npgsql.NpgsqlParameter)
Get NpgsqlParameter.ParameterName
Get NpgsqlParameter.ParameterName
Set NpgsqlParameter.Value = 22,34
...
String written: UPDATE prezzi SET prezzo = ((E'22.34')::money) WHERE id = 1.

The money value in the query is written using the '.' as decimal separator, but current system locale uses the ',' as decimal separator and the '.' as thousand separator, so the value insert in DB is €2.234,00.

Attached Files:

Changes:

Field Old Value Date By
status_idOpen2013-06-01 23:32fxjr
close_dateNone2013-06-01 23:32fxjr
Powered By FusionForge