Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Formatting Money

Status
Not open for further replies.

croydon

Programmer
Apr 30, 2002
253
EU
I am reading from a SQL Server table and displaying a money amount in a label on the webpage.

I cannot get this to format correctly.

For example I can see a record with a money amount of 1245.0000 but when I display this in the label I cannot get to to show as 1,245.00

Any assistance would be appreciated. Thanks.
 
whoops sorry ignore that.. I thought I was in the sql server forum
 
A label doesn't have formatting masks, so you would have to do this manually. Or, you can get a third party control that will format and/or mask the data for you.

Jim
 
I have tried the following for example:

lblTotalAmountReal.Text = Format(dr
("amountReal"), "##0.00")

The result is 12450000.00

This should be 1245.00

As mentioned earlier, I can see this as a money value in the table as 1245.0000
 
lblTotalAmountReal.Text = Format(dr
("amountReal"), "{0:C}")
 
Try this as a test:

lblTotalAmountReal.Text = Format(1245.0000, "#,##0.00")
 
this may not be the best way performance wise...but you have a couple options...

create a UDF (User Definded Function) in SQL..
Code:
CREATE FUNCTION [dbo].[FormatUSD] (@dollarValue DECIMAL(15, 2))
RETURNS VARCHAR(20)

AS

BEGIN

DECLARE @amount VARCHAR(20)

SET @amount = '$' + CONVERT(varchar(20),@dollarValue)

RETURN @amount

END


--usage
--SELECT id,dbo.FormatUSD(myMoney) FROM tblTable


or using the front end...

 
I would just use String.Format e.g.
Code:
        Dim l As Long = 1245.0
        Dim s As String = String.Format("{0:c}", l)


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top