dataformat

alaric

Well-known member
Joined
Oct 12, 2005
Messages
53
Programming Experience
Beginner
[RESOLVED] dataformat

Hi,

How to do this? I braking my brains on this one.:confused:
In a bound winform i use the following to display the data in a textbox
VB.NET:
[SIZE=2][COLOR=#008000]
[COLOR=black]Textbox1.DataBindings.Add("text", DataSource, "Field")[/COLOR]
[/COLOR][/SIZE]

this offcourse works fine.
however,
this value is in the database as currency and is diplayed as 10,0000 (representing €10)

(I know how to convert it to currency and it is displayed as € 10,00. But I think this is confusing for the user when changing this value, he/she might think that the '€' has te be typed to)

therefor, I just want this value to be displayed as 10,00 (2 digits instead of 4) and make a label wit the '€' sign behind the text box

thanks in advance
 
Last edited:
I must admit without sitting down and having a go at this problem, i cant say that i'd have an absolute answer for you but here's a couple of things of the top of my head. Could you....

Set the MaxLength Property of the textbox to 4? (This may be a long shot!!)

Get the value in the datatable before you bind it to the control, And adjust it beforehand, maybe by trimming off some of the trailing zeros? (Again a Long Shot. And i apologise if i'm talking absolute rubbish here!!):)
 
Format output

Formatting Output with Format Functions
Format functions:
Function String Value

FormatNumber(12345.628, 2) 12,345.62

The value of FormatNumber(n, r) is the string containing the number n rounded to r decimal places and displayed with commas as thousands separators.


read up on:
FormatNumber
FormatCurrency
FormatPercent

Hope this gets you pointed in the right direction.
 
I would be inclined to use the ToString method rather than those Runtime functions. ToString("c") for standard currency, ToString("n2") for two decimal places, etc. You can search the help/MSDN for topics entitled "Standard Numeric Format Strings" and "Custom Numeric Format Strings" for more information on what you can pass to ToString.
 
Back
Top