Solved

How to keep currency formatting of substring in string?

Posted on 2006-11-23
11
185 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
Comment Utility
try
Format
0
 

Author Comment

by:JamesJMcDonnell
Comment Utility
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
Comment Utility
       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
Comment Utility
0
 

Author Comment

by:JamesJMcDonnell
Comment Utility
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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 34

Expert Comment

by:Sancler
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

771 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

10 Experts available now in Live!

Get 1:1 Help Now