c# - Textbox format not accepting to type numbers with points -


i using code type currency amounts in textbox comma seperators , points. while typing numbers should display format(1,258,891.50). code working bt can't type points. accepting full numbers. below code....

if (textbox5.text == "")     return;  int n = textbox5.selectionstart; decimal text = convert.todecimal(textbox5.text); textbox5.text = string.format("{0:#,###0}", text); textbox5.selectionstart = n + 1; 

if currentculture has already , numbergroupseparator , . numberdecimalseparator, can use the ("n") format specifier n2 like;

textbox5.text = text.tostring("n2"); 

if not, can clone currentculture, set these values properties , use that culture second parameter in tostring method.

var clone = (cultureinfo)cultureinfo.currentculture.clone(); clone.numberformat.numbergroupseparator = ","; clone.numberformat.numberdecimalseparator = "."; textbox5.text = text.tostring("n2", clone); // 1,258,891.50 

Comments