Results 1 to 5 of 5

Thread: [RESOLVED] Decimal number to integer conversion problem.

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2014
    Posts
    15

    Resolved [RESOLVED] Decimal number to integer conversion problem.

    I have list of numbers like
    0.74
    0.34
    0.12
    0.86

    And they all convert correctly
    74
    34
    12
    86

    but if I get a number like
    0.4
    it converts to 4.. and I need it to be 40..

    I tried by multiplying every number with 100 instead of converting to integer but that doesn't work..

  2. #2
    PowerPoster
    Join Date
    Sep 2005
    Location
    Modesto, Ca.
    Posts
    5,195

    Re: Decimal number to integer conversion problem.

    I tried by multiplying every number with 100 instead of converting to integer but that doesn't work..
    Sure it does,
    Code:
        Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
    
            Dim decNum As Decimal = CDec(0.4)
            decNum = decNum * 100
            MessageBox.Show(CInt(decNum).ToString)
    
        End Sub

  3. #3
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    38,988

    Re: Decimal number to integer conversion problem.

    Yeah, I'd have to wonder how that would NOT work. For every example you showed, multiplying by 100 is all you are doing. The conversion to integer is almost irrelevant.
    My usual boring signature: Nothing

  4. #4

    Thread Starter
    New Member
    Join Date
    Aug 2014
    Posts
    15

    Re: Decimal number to integer conversion problem.

    Quote Originally Posted by Shaggy Hiker View Post
    Yeah, I'd have to wonder how that would NOT work. For every example you showed, multiplying by 100 is all you are doing. The conversion to integer is almost irrelevant.
    I had to make custom functions since the numbers I had weren't decimal numbers.. They had dots instead of commas. That is why it VB.Net couldn't convert correctly..

  5. #5
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    38,988

    Re: [RESOLVED] Decimal number to integer conversion problem.

    The comma is only used as a decimal indicator in certain parts of the world. The period (dot) is used as the decimal separator in the US, and possibly all of North America. So, it appears that the issue is just one of localization. .NET certainly doesn't have any problem converting what you just described.
    My usual boring signature: Nothing

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