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 ?

5 Years
Discussion Span
Last Post by codevigilante
TEXTBOX FORMATTING in a single statement.

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

Example :


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

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/

Edited by Majestics


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


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).

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.