We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now

x

How to convert nvarchar to money data format

Medium Priority
253 Views
Last Modified: 2012-05-06
I have a label that displays a budget number:

<asp:Label runat="server" ID="lblActualTransRevenue" CssClass="form" ></asp:Label>

the label is getting its value from here"

 Private Sub txtSupRev_TextChanged(ByVal sender As Object, ByVal e As EventArgs) Handles txtSupRev.TextChanged

        If txtSupRev.Text.Length > 0 Then
            Me.lblActualGrossRevenue.Text = CInt(Me.lblActualTransRevenue.Text) + CInt(Me.txtSupRev.Text)
        Else
            Me.lblActualGrossRevenue.Text = ""
        End If
    End Sub

How do I display 104978 to 104,978?
Comment
Watch Question

I thought you got this resolved in the other post.  Has it not got resolved?  Can you try this link?
http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/Q_23158716.html
Dirk HaestProject manager
CERTIFIED EXPERT

Commented:
Did you take a look at the format-function ?

dim yourValue as integer = 104978
dim str as string = string.Format("{0:c}", yourValue );
check formatcurrency too

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Author

Commented:
Hod do I mingle this in with my code:

Dim numInfo As Double = 23345D
        Dim result As String = numInfo.ToString("C")
        Response.Write(result.Substring(0, result.IndexOf(".")))

Private Sub txtSupRev_TextChanged(ByVal sender As Object, ByVal e As EventArgs) Handles txtSupRev.TextChanged

        If txtSupRev.Text.Length > 0 Then
            Me.lblActualGrossRevenue.Text = CInt(Me.lblActualTransRevenue.Text) + CInt(Me.txtSupRev.Text)
        Else
            Me.lblActualGrossRevenue.Text = ""
        End If
    End Sub
Dirk HaestProject manager
CERTIFIED EXPERT

Commented:
Do you mean that Me.lblActualGrossRevenue.Text must be formatted ?
Private Sub txtSupRev_TextChanged(ByVal sender As Object, ByVal e As EventArgs) Handles txtSupRev.TextChanged
 
        If txtSupRev.Text.Length > 0 Then
            Me.lblActualGrossRevenue.Text = (CInt(Me.lblActualTransRevenue.Text) + CInt(Me.txtSupRev.Text)).ToString("C")
        Else
            Me.lblActualGrossRevenue.Text = ""
        End If
    End Sub

Open in new window

Author

Commented:
Yes and also txtSupRev
Dirk HaestProject manager
CERTIFIED EXPERT

Commented:
Why would you format Me.txtSupRev.Text ?
It will be summed into the variable lblActualGrossRevenue (or I see it incorrectly)

Author

Commented:
what if I type in 200000 in txtSupRev can I format the number to 200,000.00 after postback?

Author

Commented:
Conversion from string "" to type 'Integer' is not valid when I run :

 Private Sub txtACOS_TextChanged(ByVal sender As Object, ByVal e As EventArgs) Handles txtACOS.TextChanged

        If txtACOS.Text.Length > 0 Then
            Me.lblActualNetRev.Text = FormatCurrency(CInt(Me.lblAGR.Text) - CInt(Me.txtACOS.Text))
        Else
            Me.lblActualNetRev.Text = ""
        End If
    End Sub

Author

Commented:
I had no value in the first field, therefore the error.It worked fine with value.
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.