Results 1 to 4 of 4

Thread: Add money values?

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2002
    Location
    Canton, GA
    Posts
    487

    Add money values?

    Still new to this so please excuse me...

    I am adding text boxes but it will only add the whole dollar and return a whole dollar amount. I need to correct this so if someone puts 100.50 in the first text box and 100.75 in the second text box the value will return as: 100.75

    here is my code: and suggestions?

    Code:
    'Calculate Monthly Income
    
    'Initiate Variables
    Dim intTMI As Integer
    Dim intGMI As Integer
    Dim intOMI As Integer
    
    
    'Get Text Box Totals
    intGMI = CInt(txtGMI.Text)
    intOMI = CInt(txtOMI.Text)
    
    'Show Values
    intTMI = intGMI + intOMI
    lblTMI.Text = "$"+CStr(intTMI)
    lblMI.visible = true
    lblTMI.visible = true
    thanks!

    Anjari

  2. #2
    Frenzied Member dj4uk's Avatar
    Join Date
    Aug 2002
    Location
    Birmingham, UK Lobotomies: 3
    Posts
    1,131

    Re: Add money values?

    You need to use decimal types not integers - integers don't hold decimal places.

    Give a shout if you need more info.

    DJ

    If I have been helpful please rate my post. If I haven't tell me!

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2002
    Location
    Canton, GA
    Posts
    487

    Re: Add money values?

    looks great but some values are showing like this for example: $24000.0000

    2 questions... how can I show the comma and shorten the decimal places to two spaces.....For Example: $24,000.00

    Code:
    'Calculate Down Payment
    
    'Initiate Variables
    Dim decTDP As Decimal 'Total Dowm Payment
    Dim decHV As Decimal 'Home Value
    Dim decSTDP As Decimal 'Selection
    Dim decODP As Decimal  'Other Down Payment
    
    
    'Check Selection
    
    if rbYears3.Checked = True then
    decSTDP = ".03"
    
    else if rbYears5.Checked = True then
    decSTDP = ".05"
    
    
    else if rbYears10.Checked = True then
    decSTDP = ".10"
    
    else if rbYears20.Checked = True then
    decSTDP = ".20"
    
    end if
    
    'Check Other Down Payment Value
    if txtODP.Text = "" then
    txtODP.Text ="0"
    End If
    
    
    'Get Values
    decHV = CStr(lblTHV.Text) 'Total Home Value
    decODP = CStr(txtODP.Text) 'Other Down Payment
    
    'Show Values
    decTDP = decHV * decSTDP - decODP
    lblTDP.Text = CStr(decTDP)
    
    
    lblDP.visible = true
    lblTDP.visible = true
    Last edited by Anjari; Jul 14th, 2005 at 04:07 PM.

  4. #4
    Frenzied Member dj4uk's Avatar
    Join Date
    Aug 2002
    Location
    Birmingham, UK Lobotomies: 3
    Posts
    1,131

    Re: Add money values?

    Well it's not an issue when holding the value in a variable as accuracy is good however I believe you are wanting the decimal to be formated when displayed on page (converted to a string).

    A good way is to use the String.Format method which allows you to specify the output format:
    Code:
    decimal inputValue = 24000.0000;
    
    Response.Write(String.Format("${0:0,0.00}", inputValue);
    Take a look at http://www.stevex.org/CS/blogs/dotte...icles/158.aspx for more details of String Formatting - I know it says in C# and your using VB.NET but the String.Format method is still available to you.

    HTH

    DJ

    If I have been helpful please rate my post. If I haven't tell me!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width