Displaying integer part of a decimal value

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • kimiraikkonen

    Displaying integer part of a decimal value

    Hi,
    Sorry if this is so basic but i wanted to know the correct way of
    displaying a value's "only" integer part.

    I mean; if i declare a value as integer which is actually a decimal
    number, it returns upper value after .51 decimal part.

    I mean;
    Dim number as integer = 12.51 returns 13.

    If i;
    Dim number as integer = 12.49 returns 12 as well.

    I want to return only the integer part (12) in every case without
    depending on whatever decimal part is.

    Thanks
  • Teemu

    #2
    Re: Displaying integer part of a decimal value


    "kimiraikko nen" <kimiraikkonen8 5@gmail.comkirj oitti viestissä
    news:ab3a0784-0b44-49a1-ae5f-b492e85dd4d5@l1 6g2000hsh.googl egroups.com...
    Hi,
    Sorry if this is so basic but i wanted to know the correct way of
    displaying a value's "only" integer part.
    >
    I mean; if i declare a value as integer which is actually a decimal
    number, it returns upper value after .51 decimal part.
    >
    I mean;
    Dim number as integer = 12.51 returns 13.
    >
    If i;
    Dim number as integer = 12.49 returns 12 as well.
    >
    I want to return only the integer part (12) in every case without
    depending on whatever decimal part is.
    >
    Thanks
    Math.Floor for example.

    -Teemu

    Comment

    • Armin Zingler

      #3
      Re: Displaying integer part of a decimal value

      "kimiraikko nen" <kimiraikkonen8 5@gmail.comschr ieb
      Hi,
      Sorry if this is so basic but i wanted to know the correct way of
      displaying a value's "only" integer part.
      >
      I mean; if i declare a value as integer which is actually a decimal
      number, it returns upper value after .51 decimal part.
      >
      I mean;
      Dim number as integer = 12.51 returns 13.
      Option Strict On?


      Use
      number = cint(int(12.51) )


      Armin

      Comment

      • Herfried K. Wagner [MVP]

        #4
        Re: Displaying integer part of a decimal value

        "kimiraikko nen" <kimiraikkonen8 5@gmail.comschr ieb:
        Sorry if this is so basic but i wanted to know the correct way of
        displaying a value's "only" integer part.
        'Int', 'Fix', 'Math.Floor', depending on what you want.

        --
        M S Herfried K. Wagner
        M V P <URL:http://dotnet.mvps.org/>
        V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

        Comment

        • kimiraikkonen

          #5
          Re: Displaying integer part of a decimal value

          On Feb 13, 7:26 pm, "Teemu" <tsir...@hotmai l.comwrote:
          "kimiraikko nen" <kimiraikkone.. .@gmail.comkirj oitti viestissänews:a b3a0784-0b44-49a1-ae5f-b492e85dd4d5@l1 6g2000hsh.googl egroups.com...
          >
          >
          >
          Hi,
          Sorry if this is so basic but i wanted to know the correct way of
          displaying a value's "only" integer part.
          >
          I mean; if i declare a value as integer which is actually a decimal
          number, it returns upper value after .51 decimal part.
          >
          I mean;
          Dim number as integer = 12.51 returns 13.
          >
          If i;
          Dim number as integer = 12.49 returns 12 as well.
          >
          I want to return only the integer part (12) in every case without
          depending on whatever decimal part is.
          >
          Thanks
          >
          Math.Floor for example.
          >
          -Teemu
          Thanks all. Much ways there were.

          Comment

          • kimiraikkonen

            #6
            Re: Displaying integer part of a decimal value

            On Feb 13, 9:43 pm, kimiraikkonen <kimiraikkone.. .@gmail.comwrot e:
            On Feb 13, 7:26 pm, "Teemu" <tsir...@hotmai l.comwrote:
            >
            >
            >
            "kimiraikko nen" <kimiraikkone.. .@gmail.comkirj oitti viestissänews:a b3a0784-0b44-49a1-ae5f-b492e85dd4d5@l1 6g2000hsh.googl egroups.com...
            >
            Hi,
            Sorry if this is so basic but i wanted to know the correct way of
            displaying a value's "only" integer part.
            >
            I mean; if i declare a value as integer which is actually a decimal
            number, it returns upper value after .51 decimal part.
            >
            I mean;
            Dim number as integer = 12.51 returns 13.
            >
            If i;
            Dim number as integer = 12.49 returns 12 as well.
            >
            I want to return only the integer part (12) in every case without
            depending on whatever decimal part is.
            >
            Thanks
            >
            Math.Floor for example.
            >
            -Teemu
            >
            Thanks all. Much ways there were.
            As last, i'd like to know how get these functions work with the value
            in textbox?

            if i type 12.51(dot) in textbox1 and use that code;
            Dim number As Integer = TextBox1.Text
            MsgBox(Math.Flo or(number))

            i get: 1251

            and if i type 12,51 (comma) in textbox1 and use that code;
            Dim number As Integer = TextBox1.Text
            MsgBox(Math.Flo or(number))

            i get: 13 instead of 12

            Behaviour is same also with FIX function...

            Thanks!

            Comment

            • Armin Zingler

              #7
              Re: Displaying integer part of a decimal value

              "kimiraikko nen" <kimiraikkonen8 5@gmail.comschr ieb
              Thanks Armin, a shorter way i thought :-)
              >
              If TextBox1.Text.C ontains(".") = True Then
              TextBox1.Text = TextBox1.Text.R eplace(".", ",")
              End If
              You'll get an exception if you enter "1.234,56" and the "," is the
              decimal seperator as soon as you try to convert it to a number because
              two "," are not allowed.


              Armin

              Comment

              Working...