round a number to the first 10, 50, 100

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

    round a number to the first 10, 50, 100

    I have a number, for example 0.152 or 1.729 and I want to allow to round to
    the first 0.010 or 0.050 or 0.100

  • Michael A. Covington

    #2
    Re: round a number to the first 10, 50, 100

    "Jassim Rahma" <jrahma@hotmail .comwrote in message
    news:8898F322-463C-4DD1-9F67-116C42380F27@mi crosoft.com...
    >I have a number, for example 0.152 or 1.729 and I want to allow to round to
    >the first 0.010 or 0.050 or 0.100
    One approach:

    Use the Decimal data type.

    Multiply by 100, or 20, or 10.

    Round to nearest integer.

    Divide by the number you multipied by.

    But also look for built-in rounding functions.


    Comment

    • Jassim Rahma

      #3
      Re: round a number to the first 10, 50, 100

      still unable to get it..

      what I want is the following:

      0.171 round to 10 is 0.180
      0.264 round to 10 is 0.270
      0.397 round to 10 is 0.400
      1.993 round to 10 is 2.000

      using the same logic I want to round to 50 and 100



      "Michael A. Covington" <look@ai.uga.ed u.for.addresswr ote in message
      news:%23C%23cT6 NxHHA.1184@TK2M SFTNGP04.phx.gb l...
      "Jassim Rahma" <jrahma@hotmail .comwrote in message
      news:8898F322-463C-4DD1-9F67-116C42380F27@mi crosoft.com...
      >>I have a number, for example 0.152 or 1.729 and I want to allow to round
      >>to the first 0.010 or 0.050 or 0.100
      >
      One approach:
      >
      Use the Decimal data type.
      >
      Multiply by 100, or 20, or 10.
      >
      Round to nearest integer.
      >
      Divide by the number you multipied by.
      >
      But also look for built-in rounding functions.
      >

      Comment

      • Brandon Gano

        #4
        Re: round a number to the first 10, 50, 100

        Michael's method rounds to the nearest 10th, 100th, etc. If you want to
        always round up, try this instead (not tested):

        decimal value = 0.171;
        value *= 10;
        value = decimal.Ceiling (value);
        value /= 10;


        "Jassim Rahma" <jrahma@hotmail .comwrote in message
        news:29C8725E-588A-4F2B-A103-C5E34D04B59D@mi crosoft.com...
        still unable to get it..
        >
        what I want is the following:
        >
        0.171 round to 10 is 0.180
        0.264 round to 10 is 0.270
        0.397 round to 10 is 0.400
        1.993 round to 10 is 2.000
        >
        using the same logic I want to round to 50 and 100
        >
        >
        >
        "Michael A. Covington" <look@ai.uga.ed u.for.addresswr ote in message
        news:%23C%23cT6 NxHHA.1184@TK2M SFTNGP04.phx.gb l...
        >"Jassim Rahma" <jrahma@hotmail .comwrote in message
        >news:8898F32 2-463C-4DD1-9F67-116C42380F27@mi crosoft.com...
        >>>I have a number, for example 0.152 or 1.729 and I want to allow to round
        >>>to the first 0.010 or 0.050 or 0.100
        >>
        >One approach:
        >>
        >Use the Decimal data type.
        >>
        >Multiply by 100, or 20, or 10.
        >>
        >Round to nearest integer.
        >>
        >Divide by the number you multipied by.
        >>
        >But also look for built-in rounding functions.
        >>
        >

        Comment

        • Brandon Gano

          #5
          Re: round a number to the first 10, 50, 100

          Michael's method rounds to the nearest 10th, 100th, etc. If you want to
          always round up, try this instead (not tested):

          decimal value = 0.171;
          value *= 10;
          value = decimal.Ceiling (value);
          value /= 10;


          "Jassim Rahma" <jrahma@hotmail .comwrote in message
          news:29C8725E-588A-4F2B-A103-C5E34D04B59D@mi crosoft.com...
          still unable to get it..
          >
          what I want is the following:
          >
          0.171 round to 10 is 0.180
          0.264 round to 10 is 0.270
          0.397 round to 10 is 0.400
          1.993 round to 10 is 2.000
          >
          using the same logic I want to round to 50 and 100
          >
          >
          >
          "Michael A. Covington" <look@ai.uga.ed u.for.addresswr ote in message
          news:%23C%23cT6 NxHHA.1184@TK2M SFTNGP04.phx.gb l...
          >"Jassim Rahma" <jrahma@hotmail .comwrote in message
          >news:8898F32 2-463C-4DD1-9F67-116C42380F27@mi crosoft.com...
          >>>I have a number, for example 0.152 or 1.729 and I want to allow to round
          >>>to the first 0.010 or 0.050 or 0.100
          >>
          >One approach:
          >>
          >Use the Decimal data type.
          >>
          >Multiply by 100, or 20, or 10.
          >>
          >Round to nearest integer.
          >>
          >Divide by the number you multipied by.
          >>
          >But also look for built-in rounding functions.
          >>
          >

          Comment

          Working...