Converting Negative Decimal To String Loses the -

Posted by coffeeaddict on Stack Overflow See other posts from Stack Overflow or by coffeeaddict
Published on 2010-04-02T20:57:15Z Indexed on 2010/04/02 21:23 UTC
Read the original article Hit count: 252

Filed under:

I'm required to send in a negative myDecimalValue.ToString("C"); The problem is if myDecimalValue is a negative, lets say -39, after conversion I'm getting $39.00 as the string not $39.00. So I'm not sure how to go about this.

This is the utility method that takes in the decimal. If the decimal is negative, I want the ToString to show a negative

    public static BasicAmountType CreateBasicAmount(string amount, CurrencyCodeType currencyType)
    {
        BasicAmountType basicAmount = new BasicAmountType
                                          {
                                              currencyID = currencyType,
                                              Value = amount
                                          };
        return basicAmount;
    }

I could go either way, a C or F2, all I care is about getting that negative sign intothe string if the incoming decimal is negative. I suppose there's no way to do this unless I check for negativity inside my utility method here. I can't just send a negative number and expect the ToString to work and for the ToSTring to automatically see that the decimal is negative incoming?

© Stack Overflow or respective owner

Related posts about c#