Results 1 to 25 of 25

Thread: Remove decimal place (not saving variable as int)

Threaded View

  1. #16
    Addicted Member
    Join Date
    Jan 2013
    Posts
    177

    Re: Remove decimal place (not saving variable as int)

    Quote Originally Posted by diazdar View Post
    Dim minimumValue As String

    if i change it, it renders ' minimumValue = minimumValue.Replace(".", "")'
    as useless since that is for a string. How can I use a replace function to change the decimal to nothing,
    and if i change it to a double

    will that work?
    Take a look at this and see if it makes sense

    vb.net Code:
    1. Imports System.Text
    2.      
    3.     Public Class Form1
    4.         Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
    5.             Dim x As String = GetNumber("9.99")
    6.             Dim newbuilder As New StringBuilder
    7.      
    8.             If x.Count < 10 Then
    9.                 MsgBox(x.Count)
    10.                 newbuilder.Append("0", 10 - x.Count)
    11.                 newbuilder.Append(x)
    12.             End If
    13.             x = newbuilder.ToString
    14.             MsgBox(x)
    15.      
    16.         End Sub
    17.         Function GetNumber(ByVal theString As String) As String
    18.             Dim sa() As Char = theString.ToCharArray
    19.             Dim builder As New StringBuilder
    20.      
    21.             For Each n In sa
    22.                 If IsNumeric(n) Then builder.Append(n)
    23.             Next
    24.             Return builder.ToString
    25.         End Function
    26.     End Class

    Quote Originally Posted by diazdar View Post
    Code:
    Dim newbuilder As New System.Text.StringBuilder
    
            If minimumValue.Count < 10 Then
                newbuilder.Append("0", 10 - minimumValue.Count)
                newbuilder.Append(minimumValue)
            End If
    minimum value is the variable. Is that correct? It still doesnt work. I changed line 1 because there was a syntax error. Is that even right?
    TRY THIS :

    vb.net Code:
    1. Dim newbuilder As New System.Text.StringBuilder
    2.  
    3.         If minimumValue.Count < 10 Then
    4.             newbuilder.Append("0", 10 - minimumValue.Count)
    5.             newbuilder.Append(minimumValue)
    6.         End If
    7. minimumValue = newbuilder.tostring
    Last edited by Crzyrio; Jun 5th, 2013 at 03:05 PM.

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