Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Other Discussions
  3. The Weird and The Wonderful
  4. Something's out of round here

Something's out of round here

Scheduled Pinned Locked Moved The Weird and The Wonderful
c++
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    PIEBALDconsult
    wrote on last edited by
    #1

    I found this code recently:

    Public Sub Round100(ByRef amount As Long)
        If (Math.IEEERemainder(CDbl(amount), CDbl(100)) <> 0) Then 
            amount = CLng(System.Math.Floor(amount / 100))
            amount += 1
            amount \*= 100
        End If
    End Sub
    
    1. Misleading name (it doesn't round) 1) Ought to be a function 2) Needless conversions (three of them) 3) Performs the divide twice 4) Should use Ceiling... or the \ operator ( X| ) "Well, it's VB; of course it's a horror!", I here you say, but according to the comments it was ported from C++:

      void Round100(long &amount)
      {
      if (fmod((double)amount, (double)100) != 0)
      {
      amount/=100;
      amount++;
      amount*=100;
      }
      }

    :doh:

    O B 2 Replies Last reply
    0
    • P PIEBALDconsult

      I found this code recently:

      Public Sub Round100(ByRef amount As Long)
          If (Math.IEEERemainder(CDbl(amount), CDbl(100)) <> 0) Then 
              amount = CLng(System.Math.Floor(amount / 100))
              amount += 1
              amount \*= 100
          End If
      End Sub
      
      1. Misleading name (it doesn't round) 1) Ought to be a function 2) Needless conversions (three of them) 3) Performs the divide twice 4) Should use Ceiling... or the \ operator ( X| ) "Well, it's VB; of course it's a horror!", I here you say, but according to the comments it was ported from C++:

        void Round100(long &amount)
        {
        if (fmod((double)amount, (double)100) != 0)
        {
        amount/=100;
        amount++;
        amount*=100;
        }
        }

      :doh:

      O Offline
      O Offline
      oggenok64
      wrote on last edited by
      #2

      Holy Lord.

      1 Reply Last reply
      0
      • P PIEBALDconsult

        I found this code recently:

        Public Sub Round100(ByRef amount As Long)
            If (Math.IEEERemainder(CDbl(amount), CDbl(100)) <> 0) Then 
                amount = CLng(System.Math.Floor(amount / 100))
                amount += 1
                amount \*= 100
            End If
        End Sub
        
        1. Misleading name (it doesn't round) 1) Ought to be a function 2) Needless conversions (three of them) 3) Performs the divide twice 4) Should use Ceiling... or the \ operator ( X| ) "Well, it's VB; of course it's a horror!", I here you say, but according to the comments it was ported from C++:

          void Round100(long &amount)
          {
          if (fmod((double)amount, (double)100) != 0)
          {
          amount/=100;
          amount++;
          amount*=100;
          }
          }

        :doh:

        B Offline
        B Offline
        Bigdeak
        wrote on last edited by
        #3

        The C++ version is easier to understand at the first view :P But yes, both are the same horror :D Horror code is one of the most amusing things in the world if you see it, but the biggest hell if you have to work with it.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups