Convert brackets (negative) to double

Hey. How to convert a negative value that doubles in parenthesis format. I currently have this.

Payment.Text = Calc_Payment().ToString("#,##0.00;(#,##0.00)");

This converts the payment to a bracket format. But I want to do the opposite. String in brace format for Double. If anyone can help.

+4
source share
1 answer

Try the following:

// using System.Globalization
double d = double.Parse("(1,000.90)", NumberStyles.AllowParentheses | 
                                      NumberStyles.AllowThousands | 
                                      NumberStyles.AllowDecimalPoint)

/* d = -1000.9 */

Ref. Double.Parse Method (String, NumberStyles) ; NumberStyles Enumeration

Note:  Monetary values ​​are better handled by the "decimal" type. From the doc:

, .

+7

Source: https://habr.com/ru/post/1525848/


All Articles