Results 1 to 14 of 14

Thread: Convert decimal fraction to integer

  1. #1

    Thread Starter
    Fanatic Member snufse's Avatar
    Join Date
    Jul 2004
    Location
    Jupiter, FL
    Posts
    912

    Convert decimal fraction to integer

    How can I easily convert a decimal fraction to an integer, example: if I have a value of 13,2 I need to show an integer value of 2

  2. #2
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,104

    Re: Convert decimal fraction to integer

    Will there always be only one decimal place, or will the length be arbitrary?
    My usual boring signature: Nothing

  3. #3
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: Convert decimal fraction to integer

    13,2
    .132
    13.2
    none of the above
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  4. #4
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,419

    Re: Convert decimal fraction to integer

    13,2 isn't a decimal fraction.

    i don't understand the question

  5. #5
    Frenzied Member
    Join Date
    Jul 2006
    Location
    MI
    Posts
    2,012

    Re: Convert decimal fraction to integer

    Ditto. There is no such thing as a decimal fraction. A fraction is one integer divided by another, like 3/8 or 11/16.

  6. #6
    Frenzied Member
    Join Date
    Mar 2006
    Location
    Pennsylvania
    Posts
    1,069

    Re: Convert decimal fraction to integer

    I think that people in England use commas in place of decimals or something..

  7. #7
    Frenzied Member
    Join Date
    Jul 2006
    Location
    MI
    Posts
    2,012

    Re: Convert decimal fraction to integer

    Yeah, I thought of that too, but I still know how you'd convert 13.2 to 2. OP needs to explain his problem a little better...

  8. #8
    Frenzied Member
    Join Date
    May 2006
    Location
    Toronto, ON
    Posts
    1,093

    Re: Convert decimal fraction to integer

    Code:
    Dim d As Decimal = 13.2
    Dim arrSplit As String() = d.ToString.Split(".")
    Dim i As Integer = Integer.Parse(arrSplit(1))
    Change the periods to commas if that's what your system uses as a decimal place.

  9. #9
    Frenzied Member
    Join Date
    Mar 2006
    Location
    Pennsylvania
    Posts
    1,069

    Re: Convert decimal fraction to integer

    I think there's an example on how to do this in the code bank of these forums.

  10. #10
    Frenzied Member
    Join Date
    Mar 2006
    Location
    Pennsylvania
    Posts
    1,069

    Re: Convert decimal fraction to integer

    Quote Originally Posted by snufse
    How can I easily convert a decimal fraction to an integer, example: if I have a value of 13,2 I need to show an integer value of 2
    Also, from the example you provide, it seems like you want to get all the numbers after the decimal point. This doesn't really have anything to do with fractions or integers. Although, as Tom suggested, you can use the Split function, if they even is what you want to do.

  11. #11
    PowerPoster
    Join Date
    Aug 2005
    Location
    College Station, TX
    Posts
    4,521

    Re: Convert decimal fraction to integer

    Quote Originally Posted by Tom Sawyer
    Code:
    Dim d As Decimal = 13.2
    Dim arrSplit As String() = d.ToString.Split(".")
    Dim i As Integer = Integer.Parse(arrSplit(1))
    Change the periods to commas if that's what your system uses as a decimal place.
    Or you can simply write...
    Code:
    Dim MyDec As Decimal = 13.2
    MessageBox.Show(MyDec.ToString.Split("."c)(1))

  12. #12
    Frenzied Member
    Join Date
    Mar 2006
    Location
    Pennsylvania
    Posts
    1,069

    Re: Convert decimal fraction to integer

    Might also want to convert the final answer to a string before putting it into a message box.

    vb.net Code:
    1. Dim MyDec As Decimal = 13.2
    2. MessageBox.Show(MyDec.ToString.Split("."c)(1).ToString())

  13. #13
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,419

    Re: Convert decimal fraction to integer

    Quote Originally Posted by Fromethius
    I think that people in England use commas in place of decimals or something..
    no they don't.

  14. #14
    Frenzied Member
    Join Date
    Mar 2006
    Location
    Pennsylvania
    Posts
    1,069

    Re: Convert decimal fraction to integer


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