4 Replies - 3021 Views - Last Post: 27 September 2016 - 09:58 AM Rate Topic: -----

#1 SniperCode   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 37
  • Joined: 06-September 16

How to make thousand separator and decimals in textbox

Posted 27 September 2016 - 04:38 AM

I'd like to input numbers in a textbox and format it with a thousand separator and two decimals.

I've tried the Masked Edit with a lot of different masks, but I just can't get it to work.

And I tried this code:

Thread.CurrentThread.CurrentCulture = new CultureInfo("fr-FR");
 
 
            double text = double.Parse(txt.Text);
            txt.Text = text.ToString("#,##");

But when I insert in the textbox for example 2500 I got 02 500 while I want 2 500.
Any suggestions ?
Thank you.

Is This A Good Question/Topic? 0
  • +

Replies To: How to make thousand separator and decimals in textbox

#2 Skydiver   User is offline

  • Code herder
  • member icon

Reputation: 7915
  • View blog
  • Posts: 26,425
  • Joined: 05-May 12

Re: How to make thousand separator and decimals in textbox

Posted 27 September 2016 - 05:38 AM

What mask are you using in your Masked Edit control?

By any chance, are you using the WinForms MaskedTextBox? If so, please do your users a major service by not using it. Its usability just sucks. None of the the key inputs when you try to enter, delete, and backspace work correctly. On paper and documentation, it looks like it's the most awesome WinForms managed control created after the GridView, but in practice it's terrible. (As an example, if it is so awesome, why are the various apps written in early 2000's that require IP addresses using the Win32 API IP Address Input common control instead of the managed MaskedTextBox?) The old dBase and FoxBase masked input boxes got the UI right. Unfortunately, the WinForms MaskedTextBox only took the visual aspects of those old console controls without following the keying and selection behavior.
Was This Post Helpful? 0
  • +
  • -

#3 SniperCode   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 37
  • Joined: 06-September 16

Re: How to make thousand separator and decimals in textbox

Posted 27 September 2016 - 07:15 AM

S

So, what do you suggest to handle this ?
Was This Post Helpful? 0
  • +
  • -

#4 SniperCode   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 37
  • Joined: 06-September 16

Re: How to make thousand separator and decimals in textbox

Posted 27 September 2016 - 08:25 AM

I found something interesting but I have a problem when I put some numbers in the textbox, the cursor comes always to the left ...
Here is the code:
doubletext=double.Parse(txt.Text);
CultureInfoculture=CultureInfo.CreateSpecificCulture("fr-FR");
txt.Text=text.ToString("N0",culture); 

Do you have any idea ?
Was This Post Helpful? 0
  • +
  • -

#5 Skydiver   User is offline

  • Code herder
  • member icon

Reputation: 7915
  • View blog
  • Posts: 26,425
  • Joined: 05-May 12

Re: How to make thousand separator and decimals in textbox

Posted 27 September 2016 - 09:58 AM

My recommendation is to use a plain old text box and use user hints and tooltips to help users enter text in an acceptable format, and then use validators to verify the input is correct, and the update the textbox with your preferred formatting in the hopes of training the users.

Alternatively, the up/down controls maybe appropriate for your input.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1