Search code examples
c++localizationlocalenumber-formattingnegative-number

Does the locale Have a Facet That Defines the Negative Symbol?


I would have expected the numpunct facet to have contained information about the character to use for the negative symbol.

Can I find this information somewhere else in the locale, or do I just have to assume that it's always '-'?


Solution

  • If we look at num_put::put for showpos it states

    For both integer and floating-point types, if showpos is set, the modifier + is prepended

    So that leads me to believe that + will always be used for representing a positive number

    Additionally [locale.numpunct]/2 has

    integer   ::= [sign] units
    sign      ::= plusminus
    plusminus ::= '+' | '-'
    

    Which I interpret as meaning it will always use - for a negative number and + if it is positive and showpos is true. If that wasn't the case I would expect it to be like

    integer   ::= [sign] units
    sign      ::= plusminus
    plusminus ::= plus | minus