11
Answers

How to make thousand separator and decimals in textbox

Jim Tat

Jim Tat

8y
488
1
I'd like to input numbers in a textbox and format it with a thousand separator and two decimals.<br /> <br /> I've tried the Masked Edit with a lot of different masks, but I just can't get it to work. <br /> <br /><div> And I tried this code: </div><div>&nbsp;<div class="dp-highlighter"><ol start="1" class="dp-c"><li class="alt"><span><span>Thread.CurrentThread.CurrentCulture&nbsp;=&nbsp;</span><span class="keyword">new</span><span>&nbsp;CultureInfo(</span><span class="string">"fr-FR"</span><span>);&nbsp;&nbsp;&nbsp;&nbsp;</span></span></li><li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></li><li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword">double</span><span>&nbsp;text&nbsp;=&nbsp;</span><span class="keyword">double</span><span>.Parse(txt.Text);&nbsp;&nbsp;&nbsp;&nbsp;</span></span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;txt.Text&nbsp;=&nbsp;text.ToString(<span class="string">"#,##"</span><span>);&nbsp;&nbsp;&nbsp; <br /></span></span></li></ol></div></div><div>&nbsp; But when I insert in the textbox for example 2500 I got 02 500 while I want 2 500.<br /> Any suggestions ? <br /> Thank you.</div><div><br /> </div>
Answers (11)