Windows Vista Forums

Displaying Currency on a VB . NET windows form
  1. #1


    MS Access Question Guest

    Displaying Currency on a VB . NET windows form

    I have a SQL Server Table, with a Money/Currency type.
    I wish to display it with a dollar sign and however much it is without any
    decimals.
    I tried using the Masked Text box control, but no luck.
    How do I display this value on a Windows Form in Visual Studio 2008 ?
    Thanks



      My System SpecsSystem Spec

  2. #2


    Gregory A. Beamer Guest

    Re: Displaying Currency on a VB . NET windows form

    =?Utf-8?B?TVMgQWNjZXNzIFF1ZXN0aW9u?=
    <MSAccessQuestion@xxxxxx> wrote in
    news:07D1697D-545F-442A-9A8C-6DF74192AA29@xxxxxx:

    > I have a SQL Server Table, with a Money/Currency type.
    > I wish to display it with a dollar sign and however much it is without
    > any decimals.
    > I tried using the Masked Text box control, but no luck.
    > How do I display this value on a Windows Form in Visual Studio 2008 ?
    > Thanks
    >
    One option is formatting the string you bind to the textbox.

    val.ToString("c");

    --
    Gregory A. Beamer
    MVP; MCP: +I, SE, SD, DBA

    Twitter: @gbworld
    Blog: http://gregorybeamer.spaces.live.com

    *******************************************
    | Think outside the box! |
    *******************************************

      My System SpecsSystem Spec

  3. #3


    MS Access Question Guest

    Re: Displaying Currency on a VB . NET windows form

    If it were a string, I would understand this. It's not a string. It is a SQL
    Server Money type column.
    Why is there not a "picture" or "format" property to put in something like
    $#,### similar to MS Access?
    A date field has a "format" property. I would think it would be similar to
    this. Can you advise ?
    Thanks,

    "Gregory A. Beamer" wrote:

    > =?Utf-8?B?TVMgQWNjZXNzIFF1ZXN0aW9u?=
    > <MSAccessQuestion@xxxxxx> wrote in
    > news:07D1697D-545F-442A-9A8C-6DF74192AA29@xxxxxx:
    >

    > > I have a SQL Server Table, with a Money/Currency type.
    > > I wish to display it with a dollar sign and however much it is without
    > > any decimals.
    > > I tried using the Masked Text box control, but no luck.
    > > How do I display this value on a Windows Form in Visual Studio 2008 ?
    > > Thanks
    > >
    >
    > One option is formatting the string you bind to the textbox.
    >
    > val.ToString("c");
    >
    > --
    > Gregory A. Beamer
    > MVP; MCP: +I, SE, SD, DBA
    >
    > Twitter: @gbworld
    > Blog: http://gregorybeamer.spaces.live.com
    >
    > *******************************************
    > | Think outside the box! |
    > *******************************************
    >

      My System SpecsSystem Spec

  4. #4


    Morten Wennevik [C# MVP] Guest

    Re: Displaying Currency on a VB . NET windows form

    In .Net the database type 'money' would translate to the .Net type 'decimal'.
    Calling decimal.ToString("c") would create a currency formatted string
    object containing the actual value as well as a currency symbol from the
    current culture. You can put this string object in a TextBox. If you only
    want the integer value you can use c0 as the format to specify 0 decimal
    places. The value would be rounded.

    decimal d = 12.87m;
    textBox1.Text = d.ToString("c0", CultureInfo.GetCultureInfo("en-US")); // $13

    Specifying the CultureInfo is optional, but on my Norwegian system it would
    otherwise output "kr 13";

    --
    Happy Coding!
    Morten Wennevik [C# MVP]


    "MS Access Question" wrote:

    > If it were a string, I would understand this. It's not a string. It is a SQL
    > Server Money type column.
    > Why is there not a "picture" or "format" property to put in something like
    > $#,### similar to MS Access?
    > A date field has a "format" property. I would think it would be similar to
    > this. Can you advise ?
    > Thanks,
    >
    > "Gregory A. Beamer" wrote:
    >

    > > =?Utf-8?B?TVMgQWNjZXNzIFF1ZXN0aW9u?=
    > > <MSAccessQuestion@xxxxxx> wrote in
    > > news:07D1697D-545F-442A-9A8C-6DF74192AA29@xxxxxx:
    > >

    > > > I have a SQL Server Table, with a Money/Currency type.
    > > > I wish to display it with a dollar sign and however much it is without
    > > > any decimals.
    > > > I tried using the Masked Text box control, but no luck.
    > > > How do I display this value on a Windows Form in Visual Studio 2008 ?
    > > > Thanks
    > > >
    > >
    > > One option is formatting the string you bind to the textbox.
    > >
    > > val.ToString("c");
    > >
    > > --
    > > Gregory A. Beamer
    > > MVP; MCP: +I, SE, SD, DBA
    > >
    > > Twitter: @gbworld
    > > Blog: http://gregorybeamer.spaces.live.com
    > >
    > > *******************************************
    > > | Think outside the box! |
    > > *******************************************
    > >

      My System SpecsSystem Spec

  5. #5


    VBStudioLosAngeles Guest

    Re: Displaying Currency on a VB . NET windows form

    Thank you, Morten.
    I am not exactly clear on where to put this, in the code behind forms ?
    Why am I able to "format" a date object easily with the "Format" property,
    and this is much more unintuitive ?
    Isn't there a property that just can be set on how to display the Money, as
    it should be displayed in form for intutivitive and easy reading?
    I am confused !
    Thank you !

    "Morten Wennevik [C# MVP]" wrote:

    > In .Net the database type 'money' would translate to the .Net type 'decimal'.
    > Calling decimal.ToString("c") would create a currency formatted string
    > object containing the actual value as well as a currency symbol from the
    > current culture. You can put this string object in a TextBox. If you only
    > want the integer value you can use c0 as the format to specify 0 decimal
    > places. The value would be rounded.
    >
    > decimal d = 12.87m;
    > textBox1.Text = d.ToString("c0", CultureInfo.GetCultureInfo("en-US")); // $13
    >
    > Specifying the CultureInfo is optional, but on my Norwegian system it would
    > otherwise output "kr 13";
    >
    > --
    > Happy Coding!
    > Morten Wennevik [C# MVP]
    >
    >
    > "MS Access Question" wrote:
    >

    > > If it were a string, I would understand this. It's not a string. It is a SQL
    > > Server Money type column.
    > > Why is there not a "picture" or "format" property to put in something like
    > > $#,### similar to MS Access?
    > > A date field has a "format" property. I would think it would be similar to
    > > this. Can you advise ?
    > > Thanks,
    > >
    > > "Gregory A. Beamer" wrote:
    > >

    > > > =?Utf-8?B?TVMgQWNjZXNzIFF1ZXN0aW9u?=
    > > > <MSAccessQuestion@xxxxxx> wrote in
    > > > news:07D1697D-545F-442A-9A8C-6DF74192AA29@xxxxxx:
    > > >
    > > > > I have a SQL Server Table, with a Money/Currency type.
    > > > > I wish to display it with a dollar sign and however much it is without
    > > > > any decimals.
    > > > > I tried using the Masked Text box control, but no luck.
    > > > > How do I display this value on a Windows Form in Visual Studio 2008 ?
    > > > > Thanks
    > > > >
    > > >
    > > > One option is formatting the string you bind to the textbox.
    > > >
    > > > val.ToString("c");
    > > >
    > > > --
    > > > Gregory A. Beamer
    > > > MVP; MCP: +I, SE, SD, DBA
    > > >
    > > > Twitter: @gbworld
    > > > Blog: http://gregorybeamer.spaces.live.com
    > > >
    > > > *******************************************
    > > > | Think outside the box! |
    > > > *******************************************
    > > >

      My System SpecsSystem Spec

  6. #6


    VBStudioLosAngeles Guest

    Re: Displaying Currency on a VB . NET windows form

    For Example, Morten, the SQL Server Report Writer easily displays a format
    property, where C0 can be input to make money types display as currency
    without decimals, and include the commas. I would think this same property
    would (should) be available in Visual Studio 2008 for a windows form.

    "Morten Wennevik [C# MVP]" wrote:

    > In .Net the database type 'money' would translate to the .Net type 'decimal'.
    > Calling decimal.ToString("c") would create a currency formatted string
    > object containing the actual value as well as a currency symbol from the
    > current culture. You can put this string object in a TextBox. If you only
    > want the integer value you can use c0 as the format to specify 0 decimal
    > places. The value would be rounded.
    >
    > decimal d = 12.87m;
    > textBox1.Text = d.ToString("c0", CultureInfo.GetCultureInfo("en-US")); // $13
    >
    > Specifying the CultureInfo is optional, but on my Norwegian system it would
    > otherwise output "kr 13";
    >
    > --
    > Happy Coding!
    > Morten Wennevik [C# MVP]
    >
    >
    > "MS Access Question" wrote:
    >

    > > If it were a string, I would understand this. It's not a string. It is a SQL
    > > Server Money type column.
    > > Why is there not a "picture" or "format" property to put in something like
    > > $#,### similar to MS Access?
    > > A date field has a "format" property. I would think it would be similar to
    > > this. Can you advise ?
    > > Thanks,
    > >
    > > "Gregory A. Beamer" wrote:
    > >

    > > > =?Utf-8?B?TVMgQWNjZXNzIFF1ZXN0aW9u?=
    > > > <MSAccessQuestion@xxxxxx> wrote in
    > > > news:07D1697D-545F-442A-9A8C-6DF74192AA29@xxxxxx:
    > > >
    > > > > I have a SQL Server Table, with a Money/Currency type.
    > > > > I wish to display it with a dollar sign and however much it is without
    > > > > any decimals.
    > > > > I tried using the Masked Text box control, but no luck.
    > > > > How do I display this value on a Windows Form in Visual Studio 2008 ?
    > > > > Thanks
    > > > >
    > > >
    > > > One option is formatting the string you bind to the textbox.
    > > >
    > > > val.ToString("c");
    > > >
    > > > --
    > > > Gregory A. Beamer
    > > > MVP; MCP: +I, SE, SD, DBA
    > > >
    > > > Twitter: @gbworld
    > > > Blog: http://gregorybeamer.spaces.live.com
    > > >
    > > > *******************************************
    > > > | Think outside the box! |
    > > > *******************************************
    > > >

      My System SpecsSystem Spec

  7. #7


    Morten Wennevik [C# MVP] Guest

    Re: Displaying Currency on a VB . NET windows form

    Well,

    A DateTime or Decimal does not know or care how it is displayed, including
    wether t use dot or comma as decimal separator or how to format the date and
    time. The formatting is only interesting when you display the object in some
    way. The ToString method is often used and therefore supports number and
    time format specifiers. In the end they all have to be converted to some
    form of string to be displayed. If you try copying data from the money
    column into an excel spreadsheet you may be lucky and find that it remains a
    floating point number, but you are actually copying string values, and for me
    it fails miserably as . is a thousand separator in Norway. Excel takes a
    wild guess and guesses wrong.

    I'm not too familiar with MS Access, but a MaskedTextBox does have a Mask
    property which will take "$#,###" as a value. In fact, MaskedTextBox is
    based on the MaskedEdit control in VB6 which I suspect is very close to what
    MS Access uses.

    I have a sneaking suspicion that I'm not answering what you are asking, and
    if so I apologize.

    --
    Happy Coding!
    Morten Wennevik [C# MVP]


    "VBStudioLosAngeles" wrote:

    > Thank you, Morten.
    > I am not exactly clear on where to put this, in the code behind forms ?
    > Why am I able to "format" a date object easily with the "Format" property,
    > and this is much more unintuitive ?
    > Isn't there a property that just can be set on how to display the Money, as
    > it should be displayed in form for intutivitive and easy reading?
    > I am confused !
    > Thank you !
    >
    > "Morten Wennevik [C# MVP]" wrote:
    >

    > > In .Net the database type 'money' would translate to the .Net type 'decimal'.
    > > Calling decimal.ToString("c") would create a currency formatted string
    > > object containing the actual value as well as a currency symbol from the
    > > current culture. You can put this string object in a TextBox. If you only
    > > want the integer value you can use c0 as the format to specify 0 decimal
    > > places. The value would be rounded.
    > >
    > > decimal d = 12.87m;
    > > textBox1.Text = d.ToString("c0", CultureInfo.GetCultureInfo("en-US")); // $13
    > >
    > > Specifying the CultureInfo is optional, but on my Norwegian system it would
    > > otherwise output "kr 13";
    > >
    > > --
    > > Happy Coding!
    > > Morten Wennevik [C# MVP]
    > >
    > >
    > > "MS Access Question" wrote:
    > >

    > > > If it were a string, I would understand this. It's not a string. It is a SQL
    > > > Server Money type column.
    > > > Why is there not a "picture" or "format" property to put in something like
    > > > $#,### similar to MS Access?
    > > > A date field has a "format" property. I would think it would be similar to
    > > > this. Can you advise ?
    > > > Thanks,
    > > >
    > > > "Gregory A. Beamer" wrote:
    > > >
    > > > > =?Utf-8?B?TVMgQWNjZXNzIFF1ZXN0aW9u?=
    > > > > <MSAccessQuestion@xxxxxx> wrote in
    > > > > news:07D1697D-545F-442A-9A8C-6DF74192AA29@xxxxxx:
    > > > >
    > > > > > I have a SQL Server Table, with a Money/Currency type.
    > > > > > I wish to display it with a dollar sign and however much it is without
    > > > > > any decimals.
    > > > > > I tried using the Masked Text box control, but no luck.
    > > > > > How do I display this value on a Windows Form in Visual Studio 2008 ?
    > > > > > Thanks
    > > > > >
    > > > >
    > > > > One option is formatting the string you bind to the textbox.
    > > > >
    > > > > val.ToString("c");
    > > > >
    > > > > --
    > > > > Gregory A. Beamer
    > > > > MVP; MCP: +I, SE, SD, DBA
    > > > >
    > > > > Twitter: @gbworld
    > > > > Blog: http://gregorybeamer.spaces.live.com
    > > > >
    > > > > *******************************************
    > > > > | Think outside the box! |
    > > > > *******************************************
    > > > >

      My System SpecsSystem Spec

Displaying Currency on a VB . NET windows form problems?

Similar Threads
Thread Thread Starter Forum Replies Last Post
Changes made to Outlook form don't stay with form when mailed. Fabes346 VB Script 0 01 Mar 2010
Sidebar Currency Convertor Dogberry Software 1 26 Jan 2010
Start a new thread to show form - Form never shows Curious .NET General 2 29 Oct 2009
Currency Calculator sparrow91 General Discussion 4 23 Jul 2009
Windows Sidebar - Currency not updating Andy Vista General 2 20 Jun 2008