formatting numbers in textbox control

give format to the text introduced by user

Page 1 of 1

5 Replies - 13072 Views - Last Post: 28 April 2012 - 10:14 AM Rate Topic: -----

#1 babachob  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 02-April 09

formatting numbers in textbox control

Posted 15 May 2009 - 12:28 PM

hi all, i dont know how to do this, quickly discribe, im doing an application that use superficies and costs; im using textbox controls to show and get values, but i dont know the way to give format to the text, thousands separator and decimal separator, like 120,000.00. I mean, formatting text value asigned via code and keyboard.
thanks in advance.

excuse the grammar.
Is This A Good Question/Topic? 0
  • +

Replies To: formatting numbers in textbox control

#2 eclipsed4utoo  Icon User is offline

  • Not Your Ordinary Programmer
  • member icon

Reputation: 1524
  • View blog
  • Posts: 5,960
  • Joined: 21-March 08

Re: formatting numbers in textbox control

Posted 15 May 2009 - 12:45 PM

would displaying as money work?

decimal cost = 120000;
textBox1.Text = string.Format("{0:c}", cost);


Was This Post Helpful? 0
  • +
  • -

#3 babachob  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 02-April 09

Re: formatting numbers in textbox control

Posted 15 May 2009 - 03:17 PM

View Posteclipsed4utoo, on 15 May, 2009 - 11:45 AM, said:

would displaying as money work?

decimal cost = 120000;
textBox1.Text = string.Format("{0:c}", cost);




thanks for reply, that way is good when the value is setting via code, but when the user gives the value, actually a have a textbox only for numbers and a point.
Was This Post Helpful? 0
  • +
  • -

#4 eclipsed4utoo  Icon User is offline

  • Not Your Ordinary Programmer
  • member icon

Reputation: 1524
  • View blog
  • Posts: 5,960
  • Joined: 21-March 08

Re: formatting numbers in textbox control

Posted 15 May 2009 - 03:44 PM

use the key down event. then try to convert the inputted text to a decimal. If it works, allow the key. if it doesn't, then cancel the key input.
Was This Post Helpful? 0
  • +
  • -

#5 babachob  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 02-April 09

Re: formatting numbers in textbox control

Posted 15 May 2009 - 05:09 PM

thanks for your help, i solved the first one, i would to make a mask for the inputted text, any idea?
Was This Post Helpful? 0
  • +
  • -

#6 master_lam  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 28-April 12

Re: formatting numbers in textbox control

Posted 28 April 2012 - 10:14 AM

My link
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1