Solved

How to keep currency formatting of substring in string?

Posted on 2006-11-23
11
189 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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
 
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

740 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