problem with negative numbers show the minus sign RRS feed

  • Question

  • User-1198145585 posted

    Hi Friends
    My problem with negative numbers show the minus sign
    When a negative number minus Persian was the right number.
    That is not right and should be left up display
    A friend is someone who know how to do it right

    Example :


    Sunday, October 12, 2014 5:45 AM


  • User281315223 posted

    Since you are going to be formatting your particular value, you can use the String.Format() method to handle either positive or negative values and how you would prefer them to be formatted :

    // Positive test
    var positive = String.Format("{0:٣#,##0.00;٣#,##0.00-;0}", 42);
    Console.WriteLine(positive);  // yields "٣42.00"
    // Negative test
    var negative = String.Format("{0:٣#,##0.00;٣#,##0.00-;0}", -42);
    Console.WriteLine(negative);  // yields "٣42.00-"

    You can see a complete working example here, which will include the negative sign on the right (if the value is negative) and otherwise it will be left off. If you were using this with a variable, it would look like the following more generically :

    var result = String.Format("{0:٣#,##0.00;٣#,##0.00-;0}", yourValue);

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, October 12, 2014 8:06 AM