Skip to content

Currency symbol missing #266

Closed
Closed

Description

@pkfox

Selecting a numeric field and formatting as text fails to return the currency symbol with this format string.

Example postgres query

Select to_char(100.99,'FML999,999.00') in PgAdmin and psql outputs £100.00 ( in the UK ) , but the symbol £ coming through as a blank space ( which to me indicates an encoding problem ) in DOTNET DataTable - however if using Postgres ODBC driver the symbol comes through fine.

Activity

  1. roji commented on Sep 6, 2014

    @roji
    Member

    Sorry for not replying to this earlier.

    This is the current expected behavior of Npgsql. We set the "lc_monetary" to "C" on startup, meaning that for monetary purposes we are in a culture-invariant locale - so no currency symbol is produced. This is (currently) necessary for Npgsql to parse textual currency values without having to deal with locale variations.

    Note that setting this parameter is causing trouble elsewhere as well (#163).

    Let us research things a little, we may be able to handle currency types without setting lc_monetary to C. If this is possible it will fix both issues.

  2. roji commented on Sep 6, 2014

    @roji
    Member

    @franciscojunior, looking at our money conversion code I see this conversion code: https://github.com/npgsql/Npgsql/blob/master/Npgsql/NpgsqlTypes/NpgsqlTypeConvBackendToNative.cs#L298

    I'm not familiar with the type conversion code, but this seems to be an attempt to deal with all localized currency types. If this works, then it shouldn't be necessary to set LC_MONETARY to C, right?

    Do you have any history on this?

  3. franciscojunior commented on Sep 6, 2014

    @franciscojunior
    Member

    Hi, Shay!

    The problem I faced in the past was that on some locales, negative money
    values were sent as $(value) and I received complains where the dolar sign
    was in the middle of the value (I don't recall the locale where this
    appears.) That's why I decided to go with lc_monetary = C . This way we
    would need to parse only one type of money representation.
    Em 06/09/2014 14:21, "Shay Rojansky" [email protected] escreveu:

    @franciscojunior https://github.com/franciscojunior, looking at our
    money conversion code I see this conversion code:
    https://github.com/npgsql/Npgsql/blob/master/Npgsql/NpgsqlTypes/NpgsqlTypeConvBackendToNative.cs#L298

    I'm not familiar with the type conversion code, but this seems to be an
    attempt to deal with all localized currency types. If this works, then it
    shouldn't be necessary to set LC_MONETARY to C, right?

    Do you have any history on this?

    —
    Reply to this email directly or view it on GitHub
    #266 (comment).

  4. added this to the milestone on Sep 12, 2014
  5. pkfox commented on Sep 18, 2014

    @pkfox
    Author

    Hi all, I'm the one that posted the issue - do I take it that there's not going to be a fix on this ? It's not a huge issue for me as I've found a workaround for my purposes but surely it can't be that difficult to do ? If you can return the currency symbol in a normal string why can't it be done just because it's attached to a converted money value ? I'm obviously missing something here :-(

  6. roji commented on Sep 18, 2014

    @roji
    Member

    @pkfox, we definitely intend to work on this for the 3.0 version (as this is a breaking change). I have personally been concentrating on other issues, but sooner or later we'll get around to this.

    The point is that returning the currency symbol means giving up lc_monetary=C (invariant culture), which means we need to parse all locale versions of currency values. It's not necessary impossible but needs to cover all the cases. This is why we moved to invariant in the first place.

    So I think it will be done, but it may take some time.

  7. pkfox commented on Sep 18, 2014

    @pkfox
    Author

    Ok thanks for your reply but as to_char() returns a string I can’t see why prefixing the string with a “£” or “$” or whatever poses a problem and I don’t know what lc_monetary means :) thanks again for your time

  8. roji commented on Sep 18, 2014

    @roji
    Member

    @pkfox, we don't want to prefix the currency symbol ourselves - this is Postgresql's job. Postgresql normally returns a fully localized string, with the currency symbol, the correct separators, etc. (in text mode).

    This mode is great for purely textual operations, but when users want to receive money as double it becomes npgsql's job to parse the localized currency string. This is why at some point we decided to get rid of this headache by telling the Postgresql backend to sent invariant strings - no more localization.

    This mode is great for purely non-textual operations (doubles), but screws up the situation for textual users who want the currency symbol, separators, etc.

    Hope this makes the problem clear.

  9. pkfox commented on Sep 18, 2014

    @pkfox
    Author

    Ah I see ! Thanks for claryfing things , by the way what is lc_monetary ?

  10. roji commented on Sep 18, 2014

    @roji
    Member

    lc_monetary is just a Postgresql variable that tells the backend how to format currency types. Setting it to C makes formatting be culture-invariant.

    From http://www.postgresql.org/docs/9.3/static/runtime-config-client.html

    Sets the locale to use for formatting monetary amounts, for example with the to_char family of functions. Acceptable values are system-dependent; see Section 22.1 for more information. If this variable is set to the empty string (which is the default) then the value is inherited from the execution environment of the server in a system-dependent way.

  11. pkfox commented on Sep 18, 2014

    @pkfox
    Author

    OK thanks

  12. modified the milestone: on Jan 13, 2015
  13. self-assigned this
    on Jan 13, 2015
  14. 3 remaining items

  15. roji commented on Jan 13, 2015

    @roji
    Member

    Thanks for the offer, we can definitely use the help. Right now things are two volatile with the v3.0 rewrite, but as things stabilize then sure. Any specific area you're interested in or a feature you'd like to add?

  16. pkfox commented on Jan 13, 2015

    @pkfox
    Author

    Hi Shay, I’m interested in all of it but If anything needs some work I think it’s support for Entity Framework, I’ve tried to use it but got to the point where I realised it doesn’t map to functions yet and gave up

  17. roji commented on Jan 13, 2015

    @roji
    Member

    I admit EF it's definitely not my area in Npgsql - @Emill is the guy who knows most about that. One good point is that it's a separate project from the Npgsql core and is pretty loosely-coupled from it, so you wouldn't be affected by the massive refactoring going on in the core (at least in theory).

    I guess any pull requests which improve EF would be great, anything to add here @Emill?

  18. Emill commented on Jan 13, 2015

    @Emill
    Contributor

    That would be great. Yes, EF is quite separate from the rest of Npgsql, so
    you can start working on it if you want to. We however have a pull request
    for functions here: #129. Maybe you
    could review that first?

    2015-01-13 13:53 GMT+01:00 Shay Rojansky [email protected]:

    I admit EF it's definitely not my area in Npgsql - @Emill
    https://github.com/Emill is the guy who knows most about that. One good
    point is that it's a separate project from the Npgsql core and is pretty
    loosely-coupled from it, so you wouldn't be affected by the massive
    refactoring going on in the core (at least in theory).

    I guess any pull requests which improve EF would be great, anything to add
    here @Emill https://github.com/Emill?

    —
    Reply to this email directly or view it on GitHub
    #266 (comment).

  19. Emill commented on Jan 13, 2015

    @Emill
    Contributor

    The monetary setting lc_monetary also affects binary read/write, since it tells how many digits should be the fraction part. While I agree this is kind of broken by design that the actual value of the number should depend on a runtime parameter, we could read the lc_monetary setting. But since this is just a string of the name of the language/country (that depends on operating system), it's quite hard to figure out how many digits to use.

    Since money is classified as an obsolete data type that still exists for backwards-compatibility, and most countries (I think?) use 2 decimals, we should probably just assume it is 2 decimals. That is what we do currently anyway by setting locale to C.

  20. roji commented on Jan 13, 2015

    @roji
    Member

    Ah I didn't know binary encoding was sensitive to lc_monetary, that really sucks...

    I guess you're right though, 2 decimals sounds like the way to go.

  21. modified the milestones: , 3.0-beta1 on Mar 30, 2015
  22. modified the milestones: 3.0-beta1, on Aug 7, 2015
  23. added theissue type on Jun 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions