We're a community of 1.1M IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,080,716 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

How to make currency format for textbox ?

I want enter number digits into textbox and textbox will automaticaly convert this digits itno currncy
like this if i want enter 120 , i want textbox convert it 1,20 how to make code for it ?

3
Contributors
4
Replies
4 Hours
Discussion Span
10 Months Ago
Last Updated
5
Views
system_Broken
Newbie Poster
18 posts since Jul 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0
TEXTBOX FORMATTING in a single statement.

Textbox formating using a single line of code. I Hope this helps.

Example :

      textBox1.DataBindings.Add("Text",myDataSet,"UnitCost",true,DataSourceUpdateMode.OnValidation,0,"C");

The last parameter "C" formats the UnitCost field to Currency Format. The table below is a list of string formatting parameters that you could use.

Table of Formats
--------------------------------------------------------------------------------------------------------------------------------
Type                            Format                        Example
--------------------------------------------------------------------------------------------------------------------------------
Currency                       C                                 $1,234.50

Scientific
Exponential                    E                                 1.234.50E+004

Percentage                    P                                  45.6%

Fixed Decimal                F?                                ?=no.decimals Ex. F3=123.4000

ShortDate                     d                                  M/d/yyyy

LongDate                      D                                 MMMM dd, yyyy

Long Date 
Short Time                    f                                  dddd,MMMM dd, yyyy HH:mm aa

Long Date 
Long time                      F                                 dddd,MMMM dd yyyy HH:mm:ss:aa

Month & Day                 M                                 MMMM dd

General                        G                                 Date & Time format depends on system locale settings
-------------------------------------------------------------------------------------------------------------------------------

References http://social.msdn.microsoft.com/Forums/en-US/winforms/thread/c860168f-46e5-4786-a68d-ac69c6a7a248/

Majestics
Practically a Master Poster
696 posts since Jul 2007
Reputation Points: 209
Solved Threads: 66
Skill Endorsements: 5

i did not understand how to use this code under textbox ? plz some explain more

system_Broken
Newbie Poster
18 posts since Jul 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0

Check out the reference , I havent checked myself but it was accepted answer from msdn forum...

Majestics
Practically a Master Poster
696 posts since Jul 2007
Reputation Points: 209
Solved Threads: 66
Skill Endorsements: 5

if you want to display the value in a textbox:
sometextbox.text = String.Format("{0:C}", yourvalue);

if you are wantign to convert it to store the value in a table, you have to cast the value to a decimal:
someVariable = Decimal..Parse(yourValue).

codevigilante
Newbie Poster
1 post since Jul 2006
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page generated in 0.0667 seconds using 2.65MB