Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How to keep currency formatting of substring in string?

Posted on 2006-11-23
11
Medium Priority
?
193 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 5

Accepted Solution

by:
DEEPESH earned 1200 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
 
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 800 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
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…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

688 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