Wrox Programmer Forums
|
VB.NET General VB.NET discussions for issues that don't fall into other VB.NET forums.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB.NET section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 6th, 2006, 03:51 AM
Registered User
 
Join Date: Apr 2006
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default Formatting numbers

Hi there,
I have a list box with numbers in it. These numbers have more than ten decimal places and I wish to format them to only two decimal places. I've tried many methods without success.

I would appreciate your assistance in this issue.

Thanks

 
Old April 6th, 2006, 04:02 AM
Authorized User
 
Join Date: Nov 2005
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I take it that you load the numbers into the list box using a routine. What I would use is the FormatNumber statement.

Example:-
Dim Number as double = FormatNumber(3.14159265, 2)

Now load Number into your list box.

Number will now = 3.14

You can work the above in to your routine some how.

Let me know how you get on.



 
Old April 6th, 2006, 04:16 AM
Registered User
 
Join Date: Apr 2006
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank you for your help. I still have a problem. I am designing an application to calculate interest due on a loan. The following is the code I have written in my list box, which may make things clearer for you:

Private Sub btnInterest_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnInterest.Click
        lstInterest.Items.Clear()
        If Interval = "Fortnightly" Then
            For P = (Period * 26) - 26 To 0 Step -26
                Interest = (Instalment * 26) - (Instalment / ((1 + CalculatedRate) ^ P) * (1 - (1 + CalculatedRate) ^ -26)) / CalculatedRate
                lstInterest.Items.Add(Interest)

            Next
            lstInterest.Items.Add((Instalment * Period * 26) - Principal)
            FormatNumber(Interest, 2)
        Else
            For P = (Period * 12) - 12 To 0 Step -12
                Interest = (Instalment * 12) - (Instalment / ((1 + CalculatedRate) ^ P) * (1 - (1 + CalculatedRate) ^ -12)) / CalculatedRate
                lstInterest.Items.Add(Interest)
            Next
            lstInterest.Items.Add((Instalment * Period * 12) - Principal)
            FormatNumber(Interest, 2)
        End If
    End Sub

Please note that I have bolded your suggestion.
Thanks

 
Old April 6th, 2006, 04:42 AM
Authorized User
 
Join Date: Nov 2005
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Try this. I might have the comma 2 ',2' in the wrong place. If so try putting it after the close bracket '), 2'

Private Sub btnInterest_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnInterest.Click
        lstInterest.Items.Clear()
        If Interval = "Fortnightly" Then
            For P = (Period * 26) - 26 To 0 Step -26
                Interest = (Instalment * 26) - (Instalment / ((1 + CalculatedRate) ^ P) * (1 - (1 + CalculatedRate) ^ -26)) / CalculatedRate
                lstInterest.Items.Add(Interest)

            Next
            lstInterest.Items.Add(FormatNumber(Instalment * Period * 26) - Principal, 2)
        Else
            For P = (Period * 12) - 12 To 0 Step -12
                Interest = (Instalment * 12) - (Instalment / ((1 + CalculatedRate) ^ P) * (1 - (1 + CalculatedRate) ^ -12)) / CalculatedRate
                lstInterest.Items.Add(Interest)
            Next
            lstInterest.Items.Add(FormatNumber(Instalment * Period * 12) - Principal, 2)

        End If
End Sub






Similar Threads
Thread Thread Starter Forum Replies Last Post
Formatting numbers in vb.net mallikalapati .NET Framework 2.0 3 February 20th, 2008 07:29 AM
Incrementing numbers RubyRue ASP.NET 1.0 and 1.1 Basics 2 January 30th, 2008 12:16 AM
Ref numbers RubyRue ASP.NET 2.0 Basics 2 January 16th, 2008 11:29 AM
formatting phone numbers xslt_student XSLT 0 August 7th, 2006 04:10 PM
Page Numbers bcogney XML 3 April 13th, 2006 06:00 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.