私を助けてください、私はこれらの問題で数日間立ち往生しています。asp.net で支払いを受ける Web フォームがあり、言語は C# です。
テキストボックスは、ユーザーから通貨金額を受け入れることです。私の要件は、ユーザーがたとえば 75 を入力すると、_TextChanged イベントで 75.00 に切り替わることです。私はこの部分を働かせました。しかし、私のコードは の位置の後の 3 文字をチェックしません。余分なゼロを削除します。私の質問: 1. 入力が小数点以下 2 桁を超える場合、余分なゼロを削除するにはどうすればよいですか? 2. ユーザーがテキストボックスに数字を入力しない場合はどうすればよいですか? 試してみましたが、エラーが発生するか、コード全体が台無しになります。
protected void txtAmount_TextChanged(object sender, EventArgs e)
{
        string textBoxData = txtAmount.Text;
        int textLength = textBoxData.Length;
        int position = txtAmountToPay.Text.IndexOf("."); //Position is the decimal
        if (position == -1)
        {
            textBoxData = textBoxData + ".50"; // when you enter 75 you get 75.50
        }
        if (position == textLength -2 )
        {
            textBoxData = textBoxData + "4"; // when you enter 75.0 you get 75.04
        }
        if (position == textLength -1)
        {
            textBoxData = textBoxData + "30"; // when you enter 75. you get 75.30
        }
        if (position >= textLength - 3) // This part does not work
        {
            textBoxData == textBoxData.Replace(-3);// if user enters 75.0000 it will remove all the other digits after the two 0s after the decimal point
        }
    txtAmount.Text = textBoxData.ToString();
 }