Link to home
Start Free TrialLog in
Avatar of JamesJMcDonnell
JamesJMcDonnellFlag for United Kingdom of Great Britain and Northern Ireland

asked on

How to keep currency formatting of substring in string?

Hi Experts,

I have the code similiar to the following:

lblSubtotal.Text = decSubTotal.ToString("C") & " OR " & intVouchers.ToString & " VOUCHERS"

where decSubTotal is a decimal and intVouchers is an integer

the problem is that lblSubTotal.text loses the "£" symbol - decSubTotal.ToString("C")  on its own has the "£" symbol

How can I get the "£" symbol into the string (Adding "£" & to the front of the expression does not add in in either!)
Avatar of DEEPESH
DEEPESH

try
Format
Avatar of JamesJMcDonnell

ASKER

I had tried something like:

lblSubtotal.Text = Format(decSubTota, "c") & " OR " & intVouchers.ToString & " VOUCHERS"
but got same result i.e.no £
       Dim x As Int32
        Dim y As String
        x = 50
        TextBox1.Text = x.ToString("c")
        Label1.Text = x.ToString("c")

This code is workingon my side, ie it showing $ sign
ASKER CERTIFIED SOLUTION
Avatar of DEEPESH
DEEPESH

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Deepesh, the code you give works for me as well, it's just when the result is only one part of a larger string.
If you had dim z as string = "zzzz"  and then did: x.ToString("c") & " " & z do you still get $, because this is what does not work for me?

Your code, copied and pasted into a test project of mine, has worked perfectly for me in both 2003 and 2005 versions of VB.NET.

One form, one label (called lblSubtotal), one button, this code

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim decSubTotal As Decimal = 1.75
        Dim intVouchers As Integer = 1
        lblSubtotal.Text = decSubTotal.ToString("C") & " OR " & intVouchers.ToString & " VOUCHERS"
    End Sub

Try it in that stripped down version and see if it's the same for you.  If so, there is some issue with some other part of your code.

You say - EMPHASIS ADDED - "I have the code SIMILAR TO the following".  What is the ACTUAL code that is giving the problem?

Roger
Hi Roger,

Dim decSubTotal As Decimal = Profile.CurrentBooking.CalculateSubTotal()
Dim strFormatted As String = decSubTotal.ToString("C") & " OR " & Profile.CurrentBooking.CalculateVouchersSubTotal().ToString & " VOUCHERS"
Response.Write(strFormatted)
lblSubtotal.Text = strFormatted

gives:
£900.00 OR 10 VOUCHERS as the response output and
900.00 OR 10 VOUCHERS in the label

same effects using your code

The HTML is:
<h3>Your Shopping Cart: <asp:Label ID="lblSubtotal" runat="server" HtmlEncode="false"></asp:Label></h3>

James
One other strange thing:  

if I change html to:
<h3>Your Shopping Cart: £<asp:Label ID="lblSubtotal" runat="server" HtmlEncode="false"></asp:Label></h3>
it still gives: 900.00 OR 10 VOUCHERS

but if I change it to:
<h3>Your Shopping Cart: £<asp:Label ID="lblSubtotal" runat="server" HtmlEncode="false"></asp:Label></h3>
it gives: $900.00 OR 10 VOUCHERS

James
2nd snippet of html should read:
<h3>Your Shopping Cart: $<asp:Label ID="lblSubtotal" runat="server" HtmlEncode="false"></asp:Label></h3>

James
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
James

I've now looked at the source code for an HTM doc that shows the "£" sign, and what it has in its place is

                      &pound;

Roger