469,344 Members | 6,184 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,344 developers. It's quick & easy.

Formatting problem

I guess I still have not grasped the logic of formatting a simple label or
text box.

Why would the following not work? I need the resulting label to display
currency.

lblAmtDue.Text = CInt(txtEntries.Text) * 1.5

lblAmtDue.Text.Format("$#,##0.00")
Nov 21 '05 #1
6 1143
"Brad" <ba******@ukcdogs.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
I guess I still have not grasped the logic of formatting a simple label or
text box. .. . . lblAmtDue.Text = CInt(txtEntries.Text) * 1.5

lblAmtDue.Text.Format("$#,##0.00")


This is what VB will effective do...

lblAmtDue.Text = ( CInt(txtEntries.Text) * 1.5 ).ToString()

Call lblAmtDue.Text.Format("$#,##0.00")

I think what you need is

lblAmtDue.Text = ( CInt( txtEntries.Text ) * 1.5 ).ToString("$#,##0.00")

and I'd /strongly/ recommend adding

Option Strict On

either as a Project [default] setting or at the top of the Module.

HTH,
Phill W.
Nov 21 '05 #2
Try the Format function...

lblAmtDue.Text = Format(CInt(txtEntries.Text) * 1.5, "$#,##0.00")

or better yet

use FormatCurrency function

Greg

"Brad" <ba******@ukcdogs.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
I guess I still have not grasped the logic of formatting a simple label or
text box.

Why would the following not work? I need the resulting label to display
currency.

lblAmtDue.Text = CInt(txtEntries.Text) * 1.5

lblAmtDue.Text.Format("$#,##0.00")

Nov 21 '05 #3
Apply formatting on the integer itself.

lblAmtDue.Text = (CInt(txtEntries.Text) * 1.5).ToString("$#,##0.00")

"Brad" <ba******@ukcdogs.com> wrote in message
news:#1**************@tk2msftngp13.phx.gbl...
I guess I still have not grasped the logic of formatting a simple label or
text box.

Why would the following not work? I need the resulting label to display
currency.

lblAmtDue.Text = CInt(txtEntries.Text) * 1.5

lblAmtDue.Text.Format("$#,##0.00")

Nov 21 '05 #4
* "Brad" <ba******@ukcdogs.com> scripsit:
Why would the following not work? I need the resulting label to display
currency.


..NET Framework Developer's Guide -- Standard Numeric Format Strings
<URL:http://msdn.microsoft.com/library/en-us/cpguide/html/cpconStandardNumericFormatStrings.asp>

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Nov 21 '05 #5
Brad,
As the others have suggested, Text.Format is a function that returns a value
that is formatted, you are ignoring that value.

Rather then hard code the format to US dollars, I would use "C" a standard
format specifier for currency in region you are in.

I would recommend something like:

lblAmtDue.Text = (CInt(txtEntries.Text) * 1.5).ToString("C")

Which says take the integer value of txtEntries.Text, multiply that by 1.5,
convert the result of the multiplication to a string using the currency
format, then assign this formatted string to the Text property of lblAmtDue.

For details on Formatting in .NET see:

http://msdn.microsoft.com/library/de...ngoverview.asp

For standard numeric format strings (such as "C") see:

http://msdn.microsoft.com/library/de...matstrings.asp
I would also strongly recommend you include Option Strict On at the top of
your source files to avoid implicit conversions from Double to Text.

Hope this helps
Jay

"Brad" <ba******@ukcdogs.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
I guess I still have not grasped the logic of formatting a simple label or
text box.

Why would the following not work? I need the resulting label to display
currency.

lblAmtDue.Text = CInt(txtEntries.Text) * 1.5

lblAmtDue.Text.Format("$#,##0.00")

Nov 21 '05 #6
Hi Brad,

Because Greg is all alone in this thread, I find this one real very nice

txtEntries.Text = FormatCurrency( CDec(txtEntries.Text)* 1.5)

Cor
Nov 21 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

8 posts views Thread by gopal | last post: by
14 posts views Thread by Scott M. | last post: by
6 posts views Thread by Tomasz J | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.