私の文字列値の例
string amtStr = "{100,000,000.00}";
期待される結果/出力
double amt = -100,000,000.00
私が試したことはありますが、エラーが発生します"Cannot convert from 'string' to 'System.IFormatProvider'"
Convert.ToDouble(txtAmount.Text.ToString("#,0.00;-#,0.00"))
私の文字列値の例
string amtStr = "{100,000,000.00}";
期待される結果/出力
double amt = -100,000,000.00
私が試したことはありますが、エラーが発生します"Cannot convert from 'string' to 'System.IFormatProvider'"
Convert.ToDouble(txtAmount.Text.ToString("#,0.00;-#,0.00"))
Try this code
string amtStr = "{100,000,000.00}";
amtStr = amtStr.Replace("{", "-").Replace("}", "").Replace("(", "-").Replace(")", "").Trim() ;
double amt = Convert.ToDouble(amtStr);
その中かっこ {} を置き換えないと、デフォルトでは変換できません。それが適切な会計番号形式である場合、次のように NumberStyles を使用できます
string amtStr = "(100,000,000.00)";
NumberStyles styles = NumberStyles.AllowParentheses | NumberStyles.AllowTrailingSign | NumberStyles.Float | NumberStyles.AllowThousands;
string outputStr = double.Parse(amtStr, styles).ToString("#,0.00;-#,0.00");
double outputDbl = double.Parse(outputStr);