回答受付中の質問
2人が「このQ&Aが役に立った」と投票しています
回答(5件中 1~5件目)
以下、TextChangedのイベントハンドラなの
private void textHoge_TextChanged(イベントハンドラのパラメータ)
{
string text = textHoge.Text; // 入力値なの
string[] elm = text.Split('.'); // 小数点で区切るの
int i = 0
int j;
foreach (string str in elm) {
for (j; j < str.Length; j++) {
if ((i == 0)&&(j == 0)) {
if ((str[j] == '-')&&(str.Length > 1)) continue; // マイナスなの
}
if (!Char.IsDigit(str, j)) return; // 数字じゃないの
}
i++;
}
if (i != 2) return; // 実数じゃないの
if (elm[1].Length < 3) return; // 小数点以下2桁以内なの
int len = elm[0].Length + 1 + 2;
textHoge.Text = text.Remove(len); // 小数点以下2桁にするの
}
投稿日時 - 2010-09-10 06:09:10
OKWaveのオススメ
おすすめリンク