Solved

How to keep currency formatting of substring in string?

Posted on 2006-11-23
11
186 Views
Last Modified: 2010-04-23
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!)
0
Comment
Question by:JamesJMcDonnell
  • 5
  • 3
  • 3
11 Comments
 
LVL 5

Expert Comment

by:DEEPESH
ID: 18002412
try
Format
0
 

Author Comment

by:JamesJMcDonnell
ID: 18002440
I had tried something like:

lblSubtotal.Text = Format(decSubTota, "c") & " OR " & intVouchers.ToString & " VOUCHERS"
but got same result i.e.no £
0
 
LVL 5

Expert Comment

by:DEEPESH
ID: 18002659
       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
0
 
LVL 5

Accepted Solution

by:
DEEPESH earned 300 total points
ID: 18002669
0
 

Author Comment

by:JamesJMcDonnell
ID: 18002787
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?

0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 34

Expert Comment

by:Sancler
ID: 18005255
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
0
 

Author Comment

by:JamesJMcDonnell
ID: 18007001
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
0
 

Author Comment

by:JamesJMcDonnell
ID: 18007028
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
0
 

Author Comment

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

James
0
 
LVL 34

Assisted Solution

by:Sancler
Sancler earned 200 total points
ID: 18007051
James

Didn't realise it was .asp.  I've no experience on that side and can't really help.  Having said that my GUESS is that to get a "£" sign you are going to have to use an escaped (or special, or whatever it is properly called) character in HTML.

Roger
0
 
LVL 34

Expert Comment

by:Sancler
ID: 18007220
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
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now